image_generation hosted tool, or Chat Completions with Gemini’s native image output.
Prerequisites
- An Auriko API key
- Python 3.10+ with the OpenAI SDK (
pip install openai) or the auriko SDK (pip install auriko)- OR Node.js 18+ with the OpenAI SDK (
npm install openai) or@auriko/sdk(npm install @auriko/sdk)
- OR Node.js 18+ with the OpenAI SDK (
- An image-capable model:
gemini-2.5-flash-image,gemini-3-pro-image, orgemini-3.1-flash-image
Generate images
Create a chat completion with an image-capable model and save the generated image:image_tokens in usage.completion_tokens_details reports tokens consumed by generated images. The images field is absent when no images are generated. In streaming responses, images arrive complete in a single delta chunk.
Response shape
Each entry in theimages array is a GeneratedImage object:
Generate images with the Response API
Use a supported main model with OpenAI’simage_generation hosted tool to generate images via the Response API. Specify the image model (e.g. gpt-image-1) on the tool definition:
Specify the image model (e.g.
gpt-image-1) on the image_generation tool definition, not as the top-level model. The top-level model must be a supported chat model (e.g. gpt-4o) that orchestrates the tool call. gpt-image-* models are only available through the Response API.Edit images
Send an existing image alongside a text prompt to edit it. Only gpt-image-* models support editing. Content parts must be nested inside a user message:Failed calls
Animage_generation_call output item progresses through statuses: in_progress → generating → completed or failed. A failed call has status: "failed" and result: null:
Understanding tool_usage
OpenAI Response API responses include atool_usage field with per-tool consumption metrics:
The tool type in requests is
image_generation, but the tool_usage response key is image_gen. Both names are OpenAI conventions.tool_usage is only present on OpenAI Response API responses. Gemini image generation via Chat Completions reports token counts in usage.completion_tokens_details.image_tokens instead.
Supported models
Billing
Image generation through hosted tools is billed at provider pass-through rates based on token consumption. The hosted tool cost appears:- In the dashboard request detail as Tool Cost
- In the API response at
routing_metadata.cost.hosted_tool_usd - In the SDK as
response.routing_metadata.cost.hosted_tool_usd
Related
- Vision — analyze images in chat completions
- Streaming — stream image responses chunk-by-chunk
- Extensions and thinking — pass provider-specific parameters
- Response API overview — feature support and format differences