QuickStart Guide
Last updated
Was this helpful?
Last updated
Was this helpful?
Integrate AI-generated NFTs into your app in minutes. This guide walks you through getting an API key, setting up your environment, and creating your first AI-generated NFT using either the REST API or the JavaScript/TypeScript SDK. We’ll cover both the immediate (synchronous) generation workflow and the queued (asynchronous) workflow for batch jobs, using BNB Chain Mainnet (chainId 56) by default.
Before coding, obtain an API key from the (in the ChainGPT web app under the SDK/API section). You may need to register and (each NFT generation request typically costs 1 credit). Keep your API key secret – store it in an environment variable or secure config, not in your source code. You’ll include this key in all API calls or SDK initialization.
The REST API allows you to integrate NFT generation via HTTP requests (great for backends or any language). You can test it with tools like curl or Postman. In each request, include your API key for authentication (e.g. as a Bearer token in the header).
No special SDK is needed. Ensure you have a tool to send HTTP requests:
curl (command-line) or
Postman/Insomnia (GUI) for testing.
In the examples below, we use curl
in a shell. Replace YOUR_API_KEY
with the API key from your dashboard.
To generate an AI image and its NFT metadata in one step, make a POST request to the NFT generation endpoint. Include parameters like the text prompt, target model, and blockchain chainId in JSON. For example:
prompt – The text description of the image you want (be creative!).
model – AI model to use (e.g. "velogen"
).
enhance – (Optional) set "1x"
or "2x"
to upscale/improve image quality.
steps – (Optional) number of refinement steps (e.g. 2
for velogen, higher for other models).
width/height – Dimensions of the output image in pixels (e.g. 1024×1024).
walletAddress – The blockchain address that will receive the minted NFT.
chainId – Target blockchain network (here 56
for BNB Chain mainnet).
This request generates the image and prepares the NFT data. A successful response will return a JSON payload containing the generated image (as binary or a base64 string/URL) and a collectionId
(an identifier for this generation job or NFT). You’ll use the collectionId
in the next step to mint the NFT on-chain.
Generating an image does not automatically place it on the blockchain. To mint the AI-generated art as an actual NFT token, make a second request to the minting endpoint with the collectionId
from the previous step. You can also specify a custom name, description, and symbol for your new NFT:
This will initiate an on-chain transaction to mint the NFT on the specified chain (BNB Chain in our example). The API will respond with the minting result, including details like the token ID and possibly a transaction hash or contract address. At this point, your NFT exists on-chain at the contract managed by ChainGPT’s NFT Generator, and is owned by the provided wallet address.
If you need to generate many NFTs or an entire collection in one go, or want to handle longer generation times without keeping a request open, you should use the queued asynchronous flow. In this mode, you submit a job and retrieve results later, which is ideal for bulk operations (hundreds or thousands of NFTs) or improving responsiveness in your app.
Submit a generation job to the queue:
By including "queue": true
(or a similar async flag), the API will immediately return a response with a collectionId
for your job, without waiting for all images to be generated. No images are returned yet in this immediate response.
You can then poll the API for progress using that collectionId
. For example, call a progress endpoint to check status:
This might return a status like "pending"
, "in_progress"
, and eventually "completed"
along with maybe a percentage or count of images done. Once the job is completed (all NFTs generated and ready), you can retrieve the results (the generated images and metadata will be available via the API – e.g. the final progress check might return the image URLs or data).
Finally, mint the NFTs on-chain. You could either mint each NFT individually by calling the mint endpoint for each one with the same collectionId
and different names, or if the API supports batch minting, use that. In a simple case for one NFT, reuse the mint step above. For a large collection, you might loop over the results. For example, after completion:
In practice, you would iterate over all items in the collection. The key benefit of queuing is that your generation requests don’t timeout, and you can generate large batches in parallel. Use this mode when your use case involves heavy workloads or non-blocking UX (e.g. user requests 100 NFTs and you want to email them a link when ready, instead of holding a connection open).
ChainGPT offers an official Node.js SDK (@chaingpt/nft
) that wraps the above API calls into convenient functions. This is ideal for JavaScript projects (Node backends, web frameworks, or even front-end usage with bundlers) and provides TypeScript types for safer development. The SDK handles HTTP requests, file I/O, and data parsing under the hood.
Make sure you have Node.js (and npm or yarn) installed in your environment. Initialize your project (e.g. run npm init
in a new directory if needed), then install the ChainGPT NFT SDK package:
Once installed, import and configure the SDK with your API key:
Now nftClient
is ready to use. All SDK methods are asynchronous (return promises), so you’ll typically call them inside an async
function or use .then()
.
Using the SDK, you can generate an image and then mint it with just a few lines of code. The SDK provides a generateNft()
method to create the NFT art, and a mintNft()
method to mint it on-chain. For example:
Let’s break down what this does:
generateNft({...})
takes the same fields as the API call: prompt, model, image dimensions, etc., plus the target walletAddress
and chainId
. It returns an object containing the generated image (in result.data
) and a collectionId
. In this synchronous mode, the function only resolves when the image is fully generated (this might take ~30-60 seconds for a single high-res image). We write the image to generated_nft.jpg
just as a quick check, but you could also directly use result.data
(the image bytes or URL) in your application.
mintNft({...})
takes the returned collectionId
and the NFT’s metadata (name, description, symbol) to finalize the mint. This will mint the NFT on-chain and return info about the newly minted token (for example, a token ID or transaction hash which mintInfo
would contain).
After running this code, you should have an AI-generated image saved locally and an NFT minted on BNB Chain belonging to your wallet address. 🎉
For generating larger collections or when you don’t want to block your Node.js event loop, the SDK provides a queue-based workflow. Instead of waiting for each image, you enqueue a generation task and poll for its completion. The relevant methods are generateNftWithQueue()
and getNftProgress()
.
Enqueue an NFT generation job:
The generateNftWithQueue
call returns immediately with a job descriptor (including a collectionId
for the queued task). The actual image generation happens asynchronously on ChainGPT’s servers.
Check the generation progress:
The getNftProgress()
method returns the current status of the job (e.g., in_progress, completed) and possibly progress info (like how many images are done, or a percentage). You would call this periodically until you see a completed status. Once completed, the result images and metadata are ready.
Mint the NFTs after completion:
After the job is finished, you can mint the NFTs. If multiple NFTs were generated, you might loop through them; for simplicity, here’s how to mint one of the generated NFTs (using the same collectionId
):
Each call to mintNft
mints one token. You can provide different name/description
for each, or reuse the prompt or default naming scheme. In a batch scenario, you might also use a loop or the data from the completed job to mint all NFTs in the collection.
Prompt Enhancement: Not sure how to craft the perfect prompt? The API/SDK can help improve it. There’s an enhancePrompt()
method that takes a simple prompt and returns a more detailed version. Example: await nft.enhancePrompt({ prompt: "a cat playing guitar" })
might return an enriched prompt like “A charming oil painting of a cat playing an acoustic guitar on a stage”. This can be useful to guide users or to automatically boost prompt quality before generation.
Supported Models & Settings: ChainGPT’s AI NFT Generator supports multiple models (e.g. velogen
, nebula_forge_xl
, VisionaryForge
, Dale3
) each with different style characteristics. You can experiment with them to get different art styles. Likewise, the steps
parameter controls how many refinement iterations the model runs (higher can yield more detailed images but may take longer). The SDK’s README and docs have a full list of supported model
options, image resolutions, and their compatible enhance
/steps
ranges.
Multi-Chain Support: Our examples used chainId: 56
(Binance Smart Chain mainnet). The NFT Generator supports 25+ blockchains (Ethereum, Polygon, Arbitrum, Avalanche, Cronos, Tron, Base, opBNB, and more). To target a different network, simply change the chainId
to the desired chain’s ID (for example, 1 for Ethereum mainnet, 137 for Polygon, etc.). If you’re unsure what chains are available or what their IDs are, you can fetch the list via the SDK’s getChains()
method. For example: const chains = await nft.getChains(false);
will return an array of supported mainnet chains (pass true
to include testnets). You can then pick the chainId you need.
Security: Whether using the API or SDK, treat your API key like a password. Do not expose it in client-side code or commit it to repos. In production, you’ll likely route requests through your own backend that securely injects the API key. Also, ensure the wallet address you use for minting is correct – once minted, the NFT will belong to that address on-chain. If it’s your user’s address, you might want to let them connect a wallet or provide it via your app’s UI.
Error Handling: If an API call fails (network issue, invalid parameters, or insufficient credits), you’ll get an error response. In the SDK, errors are thrown as NftError
instances. Use try/catch around SDK calls in your code. Common mistakes include wrong API key, using an unsupported image size for the chosen model, or not having enough credits. The error messages from ChainGPT should help identify the issue.
You now have a solid starting point to integrate ChainGPT’s AI NFT Generator. With these examples, you can generate unique artwork from text prompts and trust ChainGPT to handle the heavy lifting of image generation and NFT minting across multiple blockchains. For more details, check out the full API reference and SDK documentation (which include deeper dives into response formats, advanced options, and best practices).
Happy building your AI-powered NFT experiences!