GPT Image 2 API with one flat price per image
Generate and edit images with GPT Image 2 and GPT Image 2.5 through the OpenAI Images API, or queue them as jobs. One flat price per image, any size.
You need images from code, an agent or a batch script, and you want to know the cost before you send the request. Lovely Router serves the OpenAI Images API, text-to-image generations and edits, for GPT Image 2 and GPT Image 2.5. Every image costs $0.04, whatever its size or quality, and it comes out of the same prepaid balance as your model calls.
Hand it to your AI agent
Copy this prompt into Claude Code, Cursor, Codex or any coding agent. It tells the agent where the docs are and how to use your API key.
Integrate models from Lovely Router into this project through the OpenAI Images API. - Docs (read first): https://lovelyrouter.com/docs/models/images.md - Use the official OpenAI SDK with base URL https://lovelyrouter.com/v1: POST /v1/images/generations and /v1/images/edits. For long or batch work, queue jobs with POST https://lovelyrouter.com/v1/images/jobs and fetch them when done. - One flat price per image; the price list is in the docs and GET https://lovelyrouter.com/v1/models. - GET https://lovelyrouter.com/v1/models lists every model id with its price; pick one there, do not guess ids. - Auth: read my API key from the LOVELY_API_KEY environment variable and send it as `Authorization: Bearer $LOVELY_API_KEY`. Never print or commit the key. If it is not set, ask me to create one at https://lovelyrouter.com/app/keys. - Billing is prepaid: every call is charged to my balance, so test with a small request before running anything large. - Every docs page is plain Markdown; the full index is https://lovelyrouter.com/llms.txt. My task: <describe what you want to build or get>
How it works
Create a key
Sign up, top up from $5 and create a key in API keys. Image models are served in the
gpt-valuechannel group, so use a key on Auto or bound to that group.Point the OpenAI SDK at Lovely Router
Set the base URL to
https://lovelyrouter.com/v1. Requests pass through as OpenAI defines them, so the official SDKs work unchanged.Generate an image
POST /v1/images/generationsholds the connection until the image is ready and returns it as base64 inb64_json.Shellcurl https://lovelyrouter.com/v1/images/generations \ -H "Authorization: Bearer $LOVELY_API_KEY" \ -H "content-type: application/json" \ -d '{ "model": "gpt-image-2", "prompt": "A watercolor painting of a red fox in a snowy birch forest at dawn", "size": "1024x1024", "quality": "medium" }' | jq -r '.data[0].b64_json' | base64 --decode > fox.png
An image usually takes 40 seconds to 2 minutes, plus any time it waits in the queue. The gateway answers within nine minutes, so give your HTTP client a timeout of at least ten. response_format: "url" is ignored; images always come back as base64.
Models and sizes
| Model | Price | Does | Largest size |
|---|---|---|---|
gpt-image-2 | $0.04 per image | Generations and edits | 3840×2160 |
gpt-image-2.5-flare | $0.04 per image | Generations and edits | 3840×2160 |
gpt-image-2.5-sunburst | $0.04 per image | Generations and edits | 3840×2160 |
size: 1024x1024, 1536x1024, 1024x1536, 2048x2048, 3840x2160, or any WIDTHxHEIGHT with both sides multiples of 16, the long side at most 3840 pixels and at most three times the short side. auto lets the model choose.
quality: low, medium, high or auto. The price is the same for each, and it has no effect on the GPT Image 2.5 models.
output_format: png (the default), jpeg or webp, with output_compression for the last two. background: "transparent" works with png and webp.
To edit, or to give the model reference images (a product, a logo, a person, a style), send up to 16 images, and optionally a mask, to POST /v1/images/edits with any of the models: as multipart/form-data files, or as URLs in JSON. An edit costs the same as a generation.
curl https://lovelyrouter.com/v1/images/edits \
-H "Authorization: Bearer $LOVELY_API_KEY" \
-F model=gpt-image-2 \
-F image=@fox.png \
-F prompt="Make it night with a full moon" | jq -r '.data[0].b64_json' | base64 --decode > fox-night.pngImage jobs: submit now, collect later
Every image request joins a queue and starts as soon as capacity is free, so a burst waits its turn instead of failing. Each account can have up to 20 images queued or generating at once. If you'd rather not hold a connection open for minutes, use image jobs:
# Submit: returns 202 with the job id and its queue_position
curl https://lovelyrouter.com/v1/images/jobs \
-H "Authorization: Bearer $LOVELY_API_KEY" \
-H "content-type: application/json" \
-d '{"model": "gpt-image-2", "prompt": "A red fox in a snowy birch forest", "size": "1536x1024"}'
# Wait up to 60 seconds for it, then download the file
curl "https://lovelyrouter.com/v1/images/jobs/img_8c1f0e2a9b7d4f3e6a5c2b1d?wait=60" \
-H "Authorization: Bearer $LOVELY_API_KEY"
curl -o fox.png https://lovelyrouter.com/v1/images/jobs/img_8c1f0e2a9b7d4f3e6a5c2b1d/content \
-H "Authorization: Bearer $LOVELY_API_KEY"A job takes the same fields as a generation; input images make it an edit. A finished job's image stays available for 7 days. You can list your recent jobs and cancel one that is still queued. If a synchronous request isn't done after nine minutes, it answers 504 with the job id in the x-lovely-image-job header, and the image keeps generating so you can collect it as a job.
In the playground and over MCP
To try prompts and edits without code, switch the playground to Images. It runs on image jobs.
Agents can make images too. The MCP server has a generate_image tool that uses GPT Image 2.5, or GPT Image 2 when 2.5 is unavailable, at the same price per image, and takes reference images by URL. It answers with a download link that works for 24 hours without a key, plus a curl command that saves the file; get_image waits for an image that wasn't finished yet. Add the server to Claude Code:
claude mcp add --transport http lovely-tools https://lovelyrouter.com/mcp \
--header "Authorization: Bearer $LOVELY_API_KEY"Then ask: "Generate a 1536x1024 hero image of a lighthouse at dusk in flat illustration style and save it to public/hero.png."
Recipes
Use gpt-image-2 with background: "transparent" and output_format: "png", then drop the file onto any page color.
Ask for 3840x2160. It costs the same as a square thumbnail; expect a PNG of about 14 MB.
Submit jobs 20 at a time, the account's limit, and submit the next as each one finishes. Collect the results with ?wait= instead of sleeping between polls.
Send it to /v1/images/edits with a mask over the area to change and a prompt that describes the change.
Let Claude Code call generate_image over MCP while it builds a page, and save each file where the code expects it.
What you pay
One flat $0.04 per image, for generations and edits, at any size and quality. The usage object in the response is informational and doesn't change the price.
When you submit an image, its price is reserved from your balance and settled when the image is done. You are not charged when a request is refused, a job is cancelled or no image is produced. Once an image has been generated it is charged, even if your client disconnected before it arrived. There is no subscription; see pricing for the other products on the same balance.
Frequently asked questions
How much does the GPT Image 2 API cost?+
Every image costs $0.04, the same for every size and quality, for generations and edits alike. GET /v1/models shows the current price as pricing.per_image.
How long does an image take?+
Usually 40 seconds to 2 minutes, plus any time in the queue. A synchronous request waits up to nine minutes; image jobs let you submit and collect the image later.
Can I get several images from one request?+
No. n must be 1. Send parallel requests or jobs for more images, up to 20 queued or generating per account at once.
How long are generated images kept?+
A finished image job's file is available from GET /v1/images/jobs/{id}/content for 7 days. Download links from the MCP generate_image tool work for 24 hours without a key.
Am I charged if generation fails?+
No. Failed images, cancelled jobs and refused requests cost nothing, and an image that can't start within 30 minutes fails with 429 without a charge.
Is streaming or partial image output supported?+
Not yet. stream: true returns 400. Image variations (/v1/images/variations) are not available either.
The Images guide lists every parameter and status code. For text models on the same key, see the GPT API.