Choose an endpoint
Always send
model; image APIs do not choose a default model for you.
Choose a model
Find current image models with:- The supported operation, such as
text-to-image,image-to-image, orimage-edit. - The request endpoint expected by the model.
- How to send references:
image_url,image_urls,reference_image_urls, multipartimage, or JSONimages[]. - Whether the model accepts
size,aspect_ratio,resolution,quality,background,output_format, orresponse_format.
Model-specific fields
gpt-image-2style requests use OpenAI-likesize,quality, and edit fields. For generation and edits,backgroundacceptsautooropaque;transparentis not supported. Omit optional fields to use automatic defaults.- Gemini and Nano Banana image families usually use
aspect_ratio; only sendresolutionwhen the model details expose 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
Get the image
Image responses can be synchronous or asynchronous:- Synchronous responses return final
data[]withurlorb64_json. - Async responses return
id,task_id,status, and usuallypoll_url. - Use
poll_urlwhen it is present. If you need a fixed URL, callGET /v1/tasks/{id}. - Use a synchronous request when you need
b64_json; async image results use URLs.
Before launch
- 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 the field names sent. - On client timeout, check whether a task was created before retrying the create request.
- Use Usage and
billing_transaction_idfor the final charge.