← Docs

Image Model Guide

Image models use different request shapes by supplier recipe. Pick a protocol tab below.

1. Basic Calling Information

ItemDescription
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, no input.messages)
  • size — e.g. 1024x1024
  • output_format, watermark — optional
  • response_format — optional: url or b64_json (default b64_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.png
  • mask — optional PNG mask (transparent regions = edit area); curl: mask=@/path/to/mask.png
  • prompt, n, size — optional
  • response_format — optional: url or b64_json (default b64_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.