Documentation Index Fetch the complete documentation index at: https://docs.nano-gpt.com/llms.txt
Use this file to discover all available pages before exploring further.
Get your API key
Generate an API key on our API page .
Add Balance
If you haven’t deposited yet, add some funds to your balance . Minimum deposit is just $1, or $0.10 when using crypto.
API usage examples
Here’s a simple example using our OpenAI-compatible chat completions endpoint: import requests
import json
BASE_URL = "https://nano-gpt.com/api/v1"
API_KEY = "YOUR_API_KEY" # Replace with your API key
headers = {
"Authorization" : f "Bearer { API_KEY } " ,
"Content-Type" : "application/json" ,
"Accept" : "text/event-stream" # Required for SSE streaming
}
def stream_chat_completion ( messages , model = "minimax/minimax-m2.7" ):
"""
Send a streaming chat completion request using the OpenAI-compatible endpoint.
"""
data = {
"model" : model,
"messages" : messages,
"stream" : True # Enable streaming
}
response = requests.post(
f " { BASE_URL } /chat/completions" ,
headers = headers,
json = data,
stream = True
)
if response.status_code != 200 :
raise Exception ( f "Error: { response.status_code } " )
for line in response.iter_lines():
if line:
line = line.decode( 'utf-8' )
if line.startswith( 'data: ' ):
line = line[ 6 :]
if line == '[DONE]' :
break
try :
chunk = json.loads(line)
if chunk[ 'choices' ][ 0 ][ 'delta' ].get( 'content' ):
yield chunk[ 'choices' ][ 0 ][ 'delta' ][ 'content' ]
except json.JSONDecodeError:
continue
# Example usage
messages = [
{ "role" : "system" , "content" : "You are a helpful assistant." },
{ "role" : "user" , "content" : "Please explain the concept of artificial intelligence." }
]
try :
print ( "Assistant's Response:" )
for content_chunk in stream_chat_completion(messages):
print (content_chunk, end = '' , flush = True )
print ( "" )
except Exception as e:
print ( f "Error: { str (e) } " )
Routing preferences For supported open-source models, you can request routing preferences with model suffixes: { "model" : "zai-org/glm-5:fast" , "messages" : [{ "role" : "user" , "content" : "Hello" }] }
{ "model" : "zai-org/glm-5:cheap" , "messages" : [{ "role" : "user" , "content" : "Hello" }] }
Use :fast for fastest estimated completion and :cheap for lowest provider price. These are pay-as-you-go provider-selection requests. See Model Suffixes for the full list. For more detailed examples and other text generation endpoints, check out our Text Generation Guide .
OpenAI-Compatible Endpoint (v1/images/generations) You can also generate images using our OpenAI-compatible endpoint: curl https://nano-gpt.com/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "hidream",
"prompt": "A serene landscape at sunset",
"n": 1,
"size": "1024x1024"
}'
Here’s an example using the OpenAI-compatible endpoint in Python: import base64
import requests
API_KEY = "YOUR_API_KEY"
def generate_image ( prompt , model = "hidream" , size = "1024x1024" ):
response = requests.post(
"https://nano-gpt.com/v1/images/generations" ,
headers = {
"Authorization" : f "Bearer { API_KEY } " ,
"Content-Type" : "application/json"
},
json = {
"model" : model,
"prompt" : prompt,
"n" : 1 ,
"size" : size,
"response_format" : "b64_json"
}
)
response.raise_for_status()
return response.json()
# Example usage
prompt = "A serene landscape with mountains and a lake at sunset, digital art style"
result = generate_image(prompt)
image_bytes = base64.b64decode(result[ "data" ][ 0 ][ "b64_json" ])
with open ( "generated_image.png" , "wb" ) as f:
f.write(image_bytes)
print ( "Image generated successfully!" )
print ( "Image saved as 'generated_image.png'" )
For more detailed examples and other image generation options, check out our Image Generation Guide .
Submit a video generation job, then poll the status endpoint until the video is ready: RUN_ID = $( curl -s -X POST https://nano-gpt.com/api/generate-video \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "veo2-video",
"prompt": "A cinematic shot of a mountain lake at sunrise"
}' | jq -r '.runId' )
curl "https://nano-gpt.com/api/video/status?requestId= $RUN_ID " \
-H "Authorization: Bearer YOUR_API_KEY"
For more detailed examples and model-specific options, check out our Video Generation Guide .