Image Model Guide
Image models use different request shapes by supplier recipe. Pick a protocol tab below.
1. Basic Calling Information
| Item | Description |
|---|---|
| Base URL | https://tokenhub.link |
| Endpoint |
POST /v1/images/generations (sync, JSON)POST /v1/images/edits (sync, multipart — OpenAI-compatible models only)POST /v1/chat/completions (sync, JSON — Gemini image models)
|
| Authentication | Authorization: Bearer <TokenHub API Key>. Create the key in API Keys in console. |
| Model Identifier | Use model in body. See Model Catalog — e.g. wan2.6-t2i, tokenhub/gpt-image-2. |
| Content-Type | application/json (generations) · multipart/form-data (edits) |
2. Request body by supplier protocol
TokenHub routes by invocation recipe (bodyShape). Use the tab that matches your model supplier.
Text-to-image (generations)
Use application/json with a JSON object ({ ... }) in the request body.
cURL example
curl -sS "https://tokenhub.link/v1/images/generations" \
-H "Authorization: Bearer $TOKENHUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tokenhub/gpt-image-2",
"prompt": "一只橘猫在窗边,摄影风格",
"size": "1024x1024",
"n": 1
}'
Key fields
prompt— required text prompt (flat JSON, noinput.messages)size— e.g.1024x1024output_format,watermark— optionalresponse_format— optional:urlorb64_json(defaultb64_json)
Response
OpenAI-compatible JSON. By default data[0].b64_json (base64 PNG). With "response_format": "url", returns data[0].url instead.
{
"data": [{ "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..." }],
"usage": { "input_tokens": 22, "output_tokens": 0 }
}
To save b64_json as a file (macOS): python3 -c "import json,base64,sys; d=json.load(sys.stdin); open('out.png','wb').write(base64.b64decode(d['data'][0]['b64_json']))" < response.json
Image edits (OpenAI-compatible)
Use POST /v1/images/edits with multipart/form-data for tokenhub/gpt-image-2. Alibaba Wan image editing uses generations + wan2.7-image-pro — see the Wan tab.
Not JSON: edits must upload the source image as a file. Use -F form fields (curl sets multipart/form-data automatically). Do not use -d '{...}' or Content-Type: application/json.
File upload in curl: prefix the path with @, e.g. -F "image=@/path/to/image.png". Without @, curl sends the path as plain text and the gateway returns image file is required.
cURL example
curl -sS "https://tokenhub.link/v1/images/edits" \ -H "Authorization: Bearer $TOKENHUB_API_KEY" \ -F "model=tokenhub/gpt-image-2" \ -F "image=@/path/to/image.png" \ -F "prompt=给图中的主体加上一顶红色贝雷帽" \ -F "n=1" \ -F "size=1024x1024"
Key fields
image— required PNG file (< 4MB); curl:image=@/path/to/file.pngmask— optional PNG mask (transparent regions = edit area); curl:mask=@/path/to/mask.pngprompt,n,size— optionalresponse_format— optional:urlorb64_json(defaultb64_json); curl:-F "response_format=url"
Response shape is the same as generations: default data[0].b64_json; use response_format=url for a temporary URL.
| Endpoint | POST /v1/chat/completions |
| Models | tokenhub/gemini-3.1-flash-image-previewtokenhub/gemini-3-pro-image-preview |
| Note | These models use the Chat Completions API, not POST /v1/images/generations. |
Text-to-image (chat completions)
Gemini image models are multimodal chat models. Send prompts in messages; generated images are returned in choices[0].message.content as Markdown-embedded base64. The same models can also answer text-only prompts.
cURL example
curl -sS "https://tokenhub.link/v1/chat/completions" \
-H "Authorization: Bearer $TOKENHUB_API_KEY" \
-H "Content-Type: application/json" \
-H "X-TokenHub-Region: global" \
-d '{
"model": "tokenhub/gemini-3.1-flash-image-preview",
"messages": [
{
"role": "user",
"content": "画一只橘猫,摄影风格"
}
]
}'
For tokenhub/gemini-3-pro-image-preview, use the same request shape and replace model only.
Key fields
model—tokenhub/gemini-3.1-flash-image-previewortokenhub/gemini-3-pro-image-previewmessages— required array; each item needsroleandcontent(prompt string).contentis nested insidemessages[], not a top-level field.X-TokenHub-Region: global— required header for these models (global listing only).modalities,max_tokens— optional; not required for image generation.
Response
HTTP 200 with OpenAI Chat Completions JSON. The image is in choices[0].message.content as  (large string). Billing usage is in usage.completion_tokens_details.image_tokens.
{
"id": "chatcmpl-20260701120723330788097uPxDGcdz",
"object": "chat.completion",
"created": 1782907654,
"model": "gemini-3.1-flash-image-preview",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": ""
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 7,
"completion_tokens": 1120,
"total_tokens": 1127,
"prompt_tokens_details": {
"text_tokens": 7,
"image_tokens": 0
},
"completion_tokens_details": {
"text_tokens": 0,
"image_tokens": 1120
}
}
}
Extract base64 from the Markdown data URL in content, or match data:image/png;base64,([^)]+) in your client. Response bodies are typically ~2–3 MB per image.
Text-only (same endpoint)
These models also support plain Q&A without image output when the prompt does not request a picture:
curl -sS "https://tokenhub.link/v1/chat/completions" \
-H "Authorization: Bearer $TOKENHUB_API_KEY" \
-H "Content-Type: application/json" \
-H "X-TokenHub-Region: global" \
-d '{
"model": "tokenhub/gemini-3.1-flash-image-preview",
"messages": [
{ "role": "user", "content": "2+2等于几?只回答数字" }
]
}'
2. cURL Example (passthrough)
Text-to-image example using a single-turn input.messages payload:
curl -sS "https://tokenhub.link/v1/images/generations" \
-H "Authorization: Bearer $TOKENHUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "wan2.6-t2i",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "A flower shop with elegant windows, a beautiful wooden door, and fresh flowers on display."
}
]
}
]
},
"parameters": {
"prompt_extend": true,
"watermark": false,
"n": 1,
"negative_prompt": "",
"size": "1280*1280"
}
}'
On success, returns HTTP 200 with upstream JSON fields. Example response structure:
Default: DashScope JSON — image URL at output.choices[0].message.content[0].image (not OpenAI data[]). TokenHub passes through upstream fields; format is not switched via response_format on this protocol.
{
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"content": [
{
"image": "https://dashscope-xxxx.oss-accelerate.aliyuncs.com/...png",
"type": "image"
}
],
"role": "assistant"
}
}
],
"finished": true
},
"usage": {
"image_count": 1,
"input_tokens": 0,
"output_tokens": 0,
"size": "1280*1280",
"total_tokens": 0
},
"request_id": "815505c6-7c3d-49d7-b197-xxxxx"
}
Image URLs are usually temporary (commonly around 24 hours). Save files to your own storage in time.
3. Parameter Reference
3.1 Top-level Request Body
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model name, for example wan2.7-image-pro. |
input | object | Yes | Multimodal input object. Core field is input.messages. |
parameters | object | No | Generation control parameters. See the table below. |
3.2 Detailed Fields for input.messages / content
| Field | Type | Required | Description |
|---|---|---|---|
input.messages | array | Yes | Message array. Typical examples use a single user message. |
messages[].role | string | Yes | Role. Typical value is user. |
messages[].content | array | Yes | Multimodal content list; can combine text and image items. |
content[].text | string | Conditional | Text prompt. In pure text-to-image scenarios, at least one text item is required. |
content[].image | string(URL) | Conditional | Reference/edit image URL. Image editing and interactive editing commonly pass one or two images. |
3.3 Detailed Fields for parameters
| Field | Type | Required | Description |
|---|---|---|---|
negative_prompt | string | No | Negative prompt to constrain unwanted elements. |
size | string | No | Output size, for example 2K. Must use size tiers supported by the model. |
n | integer | No | Number of generated images. Group-image scenarios may use values such as 4. |
prompt_extend | boolean | No | Whether to enable prompt expansion. |
watermark | boolean | No | Whether to add watermark. |
thinking_mode | boolean | No | Whether to enable thinking mode (depending on model support). |
bbox_list | array | No | Bounding-box coordinate list for interactive editing. |
enable_sequential | boolean | No | Enable sequence consistency for grouped image generation. |
4. Official Scenario Examples (updated with TokenHub endpoints)
4.1 Text-to-Image
curl --location 'https://tokenhub.link/v1/images/generations' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TOKENHUB_API_KEY" \
--data '{
"model": "wan2.7-image-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{"text": "A flower shop with elegant windows, a beautiful wooden door, and fresh flowers on display."}
]
}
]
},
"parameters": {
"size": "2K",
"n": 1,
"watermark": false,
"thinking_mode": true
}
}'
4.2 Image Editing
curl --location 'https://tokenhub.link/v1/images/generations' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TOKENHUB_API_KEY" \
--data '{
"model": "wan2.7-image-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"},
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"},
{"text": "Apply the graffiti style from image 2 onto the car in image 1."}
]
}
]
},
"parameters": {
"size": "2K",
"n": 1,
"watermark": false
}
}'
4.3 Interactive Editing
curl --location 'https://tokenhub.link/v1/images/generations' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TOKENHUB_API_KEY" \
--data '{
"model": "wan2.7-image-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{"image": "https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp"},
{"image": "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"},
{"text": "Place the alarm clock from image 1 into the selected box in image 2, keeping scene and lighting naturally blended."}
]
}
]
},
"parameters": {
"bbox_list": [[],[[989, 515, 1138, 681]]],
"size": "2K",
"n": 1,
"watermark": false
}
}'
4.4 Group Image Generation
curl --location 'https://tokenhub.link/v1/images/generations' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TOKENHUB_API_KEY" \
--data '{
"model": "wan2.7-image-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{"text": "A cinematic four-image sequence featuring the same stray orange cat with consistent appearance: Image 1 (spring): the cat walks under blooming cherry blossoms; Image 2 (summer): the cat rests in the shade on an old street; Image 3 (autumn): the cat steps on golden fallen leaves; Image 4 (winter): the cat leaves footprints in the snow."}
]
}
]
},
"parameters": {
"enable_sequential": true,
"n": 4,
"size": "2K"
}
}'
5. Reference Links
cURL example
curl -sS "https://tokenhub.link/v1/images/generations" \
-H "Authorization: Bearer $TOKENHUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "ark/doubao-seedream-4-0-250828",
"prompt": "日落下的城市天际线,电影感光影",
"size": "1024x1024"
}'
Key fields
model+prompt+size— flat JSON (same shape as TokenHub)- Use
ark/<model_id>or canonical id from catalog