Overview
The NanoGPT API offers access to all the state-of-the-art image models. This guide covers how to use our image generation endpoint.OpenAI-Compatible Endpoint (v1/images/generations)
This endpoint follows the OpenAI specification for image generation and returns a list of base64-encoded images.Basic Image Generation
Image-to-Image with OpenAI Endpoint
The OpenAI-compatible endpoint also supports img2img generation using theimageDataUrl
parameter. Here are the different ways to provide input images:
Method 1: Upload from Local File
Method 2: Upload from Image URL
Method 3: Multiple Images (for supported models)
Some models likegpt-4o-image
, flux-kontext
, and gpt-image-1
support multiple input images:
Supported Image-to-Image Models
The following models support image input via the OpenAI endpoint: Single Image Input:flux-dev-image-to-image
- Image-to-image onlyghiblify
- Transform images to Studio Ghibli stylegemini-flash-edit
- Edit images with promptshidream-edit
- Advanced image editingbagel
- Both text-to-image and image-to-imageSDXL-ArliMix-v1
- Artistic transformationsUpscaler
- Upscale images to higher resolution
flux-kontext
- Advanced context-aware generationflux-kontext/dev
- Development version (image-to-image only)gpt-4o-image
- GPT-4 powered image generationgpt-image-1
- Advanced multi-image processing
flux-lora/inpainting
- Requires bothimageDataUrl
(base image) andmaskDataUrl
(mask)
Image Data URL Format
All images must be provided as base64-encoded data URLs:image/jpeg
orimage/jpg
image/png
image/webp
image/gif
(first frame only)
Additional Parameters for Image-to-Image
When using image-to-image models, you can include these additional parameters:Image Generation
Here’s a complete example using the Recraft model and our older API standard:Parameters
The image generation API accepts the following parameters:prompt
(string): The text description of the image you want to generatemodel
(string): The model to use for generationwidth
(integer): Width of the generated image (default: 1024)height
(integer): Height of the generated image (default: 1024)negative_prompt
(string): Things to avoid in the generated imagenImages
(integer): Number of images to generate (default: 1)num_steps
(integer): Number of denoising steps (default: 30)resolution
(string): Output resolution (default: “1024x1024”)sampler_name
(string): Sampling method (default: “DPM++ 2M Karras”)scale
(float): Guidance scale (default: 7.5)
Image-to-Image (img2img) Generation
You can use existing images as input for image generation with models that support img2img functionality, such as flux-kontext. This allows you to edit or transform existing images based on text prompts.Using Image Input
To use an image as input, include theimageDataUrl
parameter with a base64-encoded image:
Image Input Parameters
When using image input, the following additional parameters are available:imageDataUrl
(string): Base64-encoded image data URL (format:data:image/[type];base64,[data]
)kontext_max_mode
(boolean): When using flux-kontext model, enables maximum context mode for better image understanding
Supported Image Formats
The following image formats are supported for input:- JPEG/JPG (
data:image/jpeg;base64,
) - PNG (
data:image/png;base64,
) - WebP (
data:image/webp;base64,
)
img2img Example
Here’s a complete example of editing an existing image:Best Practices
-
Prompt Engineering
- Be specific and detailed in your prompts
- Include style references when needed
- Use the negative prompt to avoid unwanted elements
- For img2img, describe the changes you want relative to the input image
-
Image Quality
- Higher resolution settings produce better quality but take longer
- More steps generally mean better quality but slower generation
- Adjust the guidance scale based on how closely you want to follow the prompt
- For img2img, ensure your input image has good quality for best results
-
Cost Optimization
- Start with lower resolution for testing
- Use fewer steps during development
- Generate one image at a time unless multiple variations are needed
- Compress input images appropriately to reduce upload size
Error Handling
The API may return various error codes:- 400: Bad Request (invalid parameters)
- 401: Unauthorized (invalid API key)
- 429: Too Many Requests (rate limit exceeded)
- 500: Internal Server Error