When To Use Each Endpoint
| User workflow | Endpoint | Use when | Avoid when |
|---|---|---|---|
| Text-to-image | POST /v1/images/generations | The user starts from a prompt only | You need an official GPT Image edit flow |
| Image-to-image | POST /v1/images/generations | The model documents reference images through operation: "image-to-image" plus image_url, image_urls, or reference_image_urls | The model expects multipart edit input |
| Image edit | POST /v1/images/edits | You are editing an existing image with a supported edit model such as a GPT Image family model | You are using Nano Banana style image-to-image generation |
| Variation | POST /v1/images/variations | You maintain a legacy variation-compatible integration | You are building a new reference-image workflow |
| Status | GET /v1/tasks/{id} | A create response returns task_id, status: "pending", or poll_url | The create response already contains final data[] |
model. Image endpoints intentionally do not rely on a historical implicit default model for production traffic.
Pick A Model
Start with model discovery, then inspect the selected model’s TokenLab contract:tokenlab.public_contract_summary. Model detail pages may expose the fuller tokenlab.public_contract. Use those fields to confirm:
- The supported operation, such as
text-to-image,image-to-image, orimage-edit. - The request endpoint expected by the model.
- Which shape to use for references, such as
image_url,image_urls,reference_image_urls, multipartimage, or JSONimages[]. - Whether the model accepts
size,aspect_ratio,resolution,quality,background,output_format, orresponse_format.
Request Shape Rules
gpt-image-2style requests use OpenAI-likesize,quality, and edit fields. Leave optional fields out when you want the model or TokenLab to use automatic defaults.- Gemini and Nano Banana image families usually use
aspect_ratio; only sendresolutionwhen the model contract exposes it. - Nano Banana image-to-image belongs on
/v1/images/generationswithoperation: "image-to-image"and reference image URLs. /v1/images/generationsdoes not accept top-levelimages[]orfile_id; those are edit-flow shapes.- Remote image references must be public
httporhttpsURLs. Do not send private network URLs, embedded credentials, URL fragments, or signed URLs that may expire before processing starts.
Text-To-Image Example
Reference-Image Example
Handling Results
Image responses can be synchronous or asynchronous:- Synchronous responses return final
data[]withurlorb64_json. - Async responses return
id,task_id,status, and usuallypoll_url. - Prefer
poll_urlwhen it is present. If you need a fixed route, pollGET /v1/tasks/{id}. - Use synchronous requests when you specifically need
b64_json; async image results are URL-oriented.
Production Checklist
- Validate user inputs before calling TokenLab: prompt length, image count, URL reachability, and file type.
- Set HTTP timeouts high enough for synchronous high-resolution requests. Use async mode where available for long work.
- Store
request_id,task_id,poll_url, model, endpoint, and sanitized request shape for support. - On client timeout, check whether a task was created before retrying the create request.
- Reconcile cost with usage records and
billing_transaction_idwhen present, not with provider task IDs.
Common Errors
| Symptom | Likely cause | Fix |
|---|---|---|
400 with param: "model" | Missing explicit model | Query /v1/models?recommended_for=image and send model |
| Unsupported field | Field is not in that model’s public contract | Remove the field or choose a model/endpoint that documents it |
No b64_json on async result | Async image tasks return URL-oriented results | Use synchronous mode for base64 output |
| Reference image rejected | Wrong endpoint or private/expired URL | Match the model’s documented reference shape and use reachable URLs |
API Reference
| Topic | Reference |
|---|---|
| Create Image | Create Image |
| Edit Image | Edit Image |
| Create Image Variation | Create Image Variation |
| Get Image Status | Get Image Status |
| Get Task Status | Get Task Status |