API Reference
Image Generation
Complete guide to image generation APIs
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.
Image Generation
Here’s a complete example using the Recraft model:
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)
Best Practices
-
Prompt Engineering
- Be specific and detailed in your prompts
- Include style references when needed
- Use the negative prompt to avoid unwanted elements
-
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
-
Cost Optimization
- Start with lower resolution for testing
- Use fewer steps during development
- Generate one image at a time unless multiple variations are needed
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
Always implement proper error handling in your applications: