Image Generation (OpenAI-Compatible)
Creates an image generation for the provided prompt (OpenAI-compatible)
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.
Overview
Generate images from text prompts or base64 image inputs using the OpenAI-compatible endpoint. Responses include base64 bytes (b64_json) by default or signed URLs (url) when response_format: "url".
Endpoint
- Method/Path:
POST https://nano-gpt.com/v1/images/generations - Auth:
Authorization: Bearer <API_KEY> - Required header:
Content-Type: application/json
Request Body (JSON)
Core fields:prompt(string, required): Text prompt to generate an image from.model(string, optional): Model ID (defaulthidream).n(integer, optional): Number of images to generate (default1).size(string, optional): Requested output size or model-specific resolution value. UseGET /api/v1/image-models?detailed=trueand readsupported_parameters.resolutionsfor the selected model’s supported values.response_format(string, optional):b64_json(default) orurl.user(string, optional): End-user identifier.
imageDataUrl(string, optional): Base64 data URL for a single input image.imageDataUrls(array, optional): Multiple base64 data URLs for supported models.maskDataUrl(string, optional): Base64 mask data URL for inpainting.
strength,guidance_scale,num_inference_steps,seed,kontext_max_mode.
Response
- Each
data[i]contains eitherb64_json(default) orurl(whenresponse_format: "url"), never both. - When requesting
response_format: "url", the API may still returnb64_jsonif URL generation (upload/presign) fails, as a fallback. - Signed URLs expire after a short period (currently ~1 hour). Download promptly for long-term storage.
Examples
Notes & Limits
- Input images must be provided as base64 data URLs; download and convert remote images before sending.
- Uploads should be 4 MB or smaller after encoding. Compress or resize large assets before sending.
- Use
GET /api/v1/image-models?detailed=trueto discover current image model capabilities and supported resolution values.
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
Parameters for image generation
The text prompt to generate an image from
The model to use for generation
Number of images to generate
Requested output size or model-specific resolution value. Use GET /api/v1/image-models?detailed=true and read supported_parameters.resolutions for the selected model's supported values.
"1024x1024"
"1376x768"
"auto"
The format in which the generated images are returned. Use "b64_json" (default) to receive base64-encoded image bytes in data[i].b64_json, or "url" to receive a time-limited, signed download URL in data[i].url (expires after a short period, currently ~1 hour). Note: When requesting "url", the API may still return "b64_json" if URL generation (upload/presign) fails, as a fallback.
url, b64_json A unique identifier representing your end-user
Base64-encoded image data URL for img2img generation. Single image input for models that support image-to-image transformation. Format: data:image/[type];base64,[data]. Note: Direct URL input is not supported - images must be converted to base64 data URLs before submission.
"data:image/jpeg;base64,/9j/4AAQ..."
Array of base64-encoded image data URLs for models supporting multiple image inputs (e.g., flux-kontext, gpt-4o-image, gpt-image-1). Each URL must follow the format: data:image/[type];base64,[data]
[
"data:image/jpeg;base64,/9j/4AAQ...",
"data:image/png;base64,iVBORw0KGgo..."
]Base64-encoded mask image data URL for inpainting models (e.g., flux-lora/inpainting). White areas indicate regions to edit. Format: data:image/[type];base64,[data]
"data:image/png;base64,iVBORw0KGgo..."
Controls how much the output differs from the input image in img2img mode. Lower values produce outputs closer to the input.
0 <= x <= 1How closely the model follows the text prompt. Higher values result in images more closely aligned with the prompt.
0 <= x <= 20Number of denoising steps. More steps generally produce higher quality but take longer.
1 <= x <= 100Random seed for reproducible generation. Use the same seed with the same parameters to get identical results.
42
Enable enhanced context mode for flux-kontext model. Provides better understanding of input images.
Response
Image generation response. Each data[i] contains either { url } or { b64_json }. When requesting response_format: "url", the API may fall back to returning { b64_json } if URL generation (upload/presign) fails.
Unix timestamp of when the image was created
List of generated images. Each entry contains either a hosted URL (data[i].url) or base64-encoded bytes (data[i].b64_json), never both.
- Option 1
- Option 2
{ "url": "https://...signed-url..." }Cost of the generation
Payment source used
Remaining balance after the generation