Python
CGPT SDK Docs Python
ChainGPT AI NFT Generator SDK Documentation
The ChainGPT AI NFT Generator SDK provides a comprehensive suite of tools to create, manage, and prepare NFTs for minting. This includes enhancing prompts, generating images (synchronously and asynchronously), tracking generation progress, retrieving minting metadata, and querying supported blockchains and contract ABIs.
Table of Contents
Installation
Quick Start
SDK Initialization
NFT Service Overview
NFT Service Methods
enhance_prompt()
generate_image()
generate_nft_queue()
get_progress()
mint_nft_metadata()
get_chains()
get_abi()
Data Models & Types
Enums Reference
Error Handling
Complete Example
Best Practices
New Features
Installation
Install the ChainGPT SDK via pip:
Or add to your requirements.txt:
For development with environment variables:
Quick Start
Here's a minimal example to get you started:
SDK Initialization
Basic Initialization
Required Imports
NFT Service Overview
Access the NFT service through the client:
The NFT service provides seven main methods:
enhance_prompt(): Improve prompts for better image generation
generate_image(): Create images synchronously (fast preview)
generate_nft_queue(): Queue asynchronous NFT generation (high quality)
get_progress(): Track queued generation progress
mint_nft_metadata(): Generate metadata for blockchain minting
get_chains(): List supported blockchain networks
get_abi(): Get smart contract ABI
NFT Service Methods
enhance_prompt()
Enhances or refines a text prompt for better image generation results.
Method Signature:
Parameters:
request_data
EnhancePromptRequestModel
Yes
Request containing the prompt to enhance
Request Model (EnhancePromptRequestModel):
prompt
str
Yes
The text prompt you want to enhance
Response Model (EnhancePromptResponseModel):
statusCode
int
HTTP status code (200 for success)
message
str
Response message
data.enhancedPrompt
str
The enhanced version of your prompt
Example:
generate_image()
Generates an image synchronously based on the given prompt and parameters. Best for quick previews and testing.
Method Signature:
Parameters:
request_data
GenerateImageRequestModel
Yes
Image generation parameters
Request Model (GenerateImageRequestModel):
prompt
str
Yes
-
Text prompt for image generation
model
NFTImageModel
Yes
-
AI model to use (see Enums)
height
int
Yes
-
Image height in pixels
width
int
Yes
-
Image width in pixels
steps
int
No
Model default
Number of refinement passes for image generation. Higher values can yield more detailed images at the cost of longer generation time. Each model supports a range: for example, velogen supports 1–4 steps (default ~2), while NebulaForge XL and VisionaryForge support up to 50 (default ~25). If not provided, a model-specific default is used.
enhance
ImageEnhanceOption
No
ORIGINAL
Image enhancement level
style
str
No
None
Artistic style (e.g., "fantasy_art", "cyberpunk")
traits
List[TraitModel]
No
None
List of traits to apply
image
HttpUrl
No
None
Reference image URL for image-to-image generation
isCharacterPreserve
bool
No
False
Preserve character features from reference image
Response Model (GenerateImageResponseModel):
data.type
str
Data type (always "Buffer")
data.data
List[int]
Raw image bytes as integer array
Image-to-Image Generation:
Example:
Image-to-Image Generation:
Using Traits:
generate_nft_queue()
Initiates an asynchronous NFT image generation job. Use this for high-quality images or when you don't need immediate results.
Method Signature:
Parameters:
request_data
GenerateNFTQueueRequestModel
Yes
NFT generation parameters
Request Model (GenerateNFTQueueRequestModel):
walletAddress
str
Yes
Blockchain wallet address for the NFT
prompt
str
Yes
Text prompt for image generation
model
NFTImageModel
Yes
AI model to use
height
int
Yes
Image height in pixels
width
int
Yes
Image width in pixels
chainId
int
Yes
Blockchain network ID (see get_chains())
amount
int
Yes
Number of NFTs to generate in this batch
steps
int
No
Generation steps
enhance
ImageEnhanceOption
No
Enhancement level
style
str
No
Artistic style
traits
List[TraitModel]
No
List of traits
image
HttpUrl
No
Reference image URL for image-to-image generation
isCharacterPreserve
bool
No
Preserve character features from reference image
Response Model (GenerateNFTQueueResponseModel):
statusCode
int
HTTP status code (201 = successfully queued)
message
str
Response message
data.collectionId
str
Unique ID for tracking this generation job
Example:
get_progress()
Checks the status and progress of a queued NFT generation job.
Method Signature:
Parameters:
collection_id
str
Yes
Collection ID from generate_nft_queue() response
Response Model (NFTProgressResponseModel):
statusCode
int
HTTP status code
message
str
Response message
data.generated
bool
True if generation is complete
data.images
List[str]
IPFS URLs (only when generated=True)
data.progress
int
Progress percentage (only when processing)
Example:
mint_nft_metadata()
Generates the metadata required for minting NFTs on a blockchain. Call this after NFT generation is complete.
Method Signature:
Parameters:
request_data
MintNFTRequestModel
Yes
Metadata generation parameters
Request Model (MintNFTRequestModel):
collectionId
str
Yes
ID of completed NFT generation job
name
str
Yes
Name of the NFT
description
str
Yes
Description of the NFT
symbol
str
Yes
Symbol for the NFT collection
ids
List[int]
Yes
List of NFT IDs to mint (e.g., [1] for single NFT)
Response Model (MintNFTResponseModel):
statusCode
int
HTTP status code
message
str
Response message
data._id
str
MongoDB document ID
data._id
str
MongoDB document ID
data.name
str
NFT name
data.description
str
NFT description
data.image
str
IPFS URL for the NFT image
data.attributes
List[Dict]
NFT attributes/traits
data.collectionId
str
Collection ID
data.transaction
Any
Transaction details (if applicable)
data.__v
int
MongoDB version field
data.createdAt
str
Creation timestamp
data.updatedAt
str
Last update timestamp
data.__v
int
MongoDB version field
data.createdAt
str
Creation timestamp
data.updatedAt
str
Last update timestamp
Example:
get_chains()
Retrieves the list of supported blockchain networks for NFT operations.
Method Signature:
Parameters:
test_net
bool
No
None
True for testnets, False for mainnets, None for all
Response Model (GetChainsResponseModel):
statusCode
int
HTTP status code
message
str
Response message
data.chains
List[ChainInfoModel]
List of supported chains
Chain Info Model (ChainInfoModel):
chainId
int
Numerical chain ID
chainName
str
Chain name (e.g., "Ethereum Mainnet")
network
str
Network type ("mainnet", "testnet")
networkType
str
Additional network classification
Example:
get_abi()
Provides the ABI (Application Binary Interface) of the ChainGPT NFT smart contract for direct blockchain interaction.
Method Signature:
Parameters: None
Response Model (ContractABIResponseModel):
statusCode
int
HTTP status code
message
str
Response message
data
List[Dict]
Contract ABI as JSON objects
Example:
Data Models & Types
TraitModel
Defines NFT traits/attributes for generation:
Error Models
All methods can raise the following exceptions:
Enums Reference
NFTImageModel
Available AI models for image generation:
VELOGEN
"velogen"
Fast generation
Quick previews, testing
NEBULA_FORGE_XL
"nebula_forge_xl"
High quality
Final NFTs, detailed art
VISIONARY_FORGE
"VisionaryForge"
Balanced
General purpose
DALE3
"Dale3"
Alternative model
Experimental
ImageEnhanceOption
Image enhancement levels:
ORIGINAL
"original"
No enhancement
ENHANCE_1X
"1x"
1x enhancement
ENHANCE_2X
"2x"
2x enhancement
Error Handling
Basic Error Handling
Specific Error Scenarios
Complete Example
Here's a comprehensive example showing the full NFT creation workflow:
Best Practices
1. Resource Management
Always close the client when done:
2. Error Handling
Handle specific errors appropriately:
3. Progress Tracking
Use reasonable polling intervals:
4. Model Selection
Choose the right model for your use case:
5. Prompt Engineering
Create effective prompts:
New Features
Image-to-Image Generation
The NFT service now supports image-to-image generation, allowing you to create variations based on reference images:
Character Preservation
When using image-to-image generation, you can preserve character features from the reference image:
Enhanced Traits System
The traits system has been enhanced with better support for NFT collections:
Updated Chain Support
The chain information now includes more detailed network information:
Improved Response Structures
All API responses now follow a consistent structure with proper error handling:
This ensures better error handling and consistent data access patterns across all NFT service methods.
Last updated
Was this helpful?