The GPT Image series is called through the Token Market OpenAI-compatible image interface to process text generation images and image editing respectively.
https://api.tokensmarket.ai/v1POST /images/generationsThe endpoint remains fixed. Use the parameter documentation on this page to replace the model ID and request data.
${base_url}/images/generations${base_url}/images/editsAll media generation requests are authenticated through the Token Market gateway. JSON requests use application/json; multipart requests are automatically generated by the client Content-Type boundary.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
Authorization | string | Yes | — | Append the current workspace API Key after Bearer. Options / constraints: Bearer <API_KEY>. |
Content-Type | string | Yes | application/json | Send the request body as JSON. |
Text generation uses /images/generations. model and prompt are required; all other controls apply only when supported by the current model and channel.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | The GPT Image model ID to call. Options / constraints: gpt-image-2. |
prompt | string | Yes | — | A prompt describing the desired scene, composition, subject, lighting, materials, and style. |
n | integer | No | — | Number of images to generate. Options / constraints: Follow the current model's supported range. |
stream | boolean | No | — | Set to true to request SSE. |
moderation | string | No | — | Content moderation controls when supported by the model. |
partial_images | integer | No | — | Number of intermediate images returned when supported by the model. |
output_compression | integer | No | — | Output compression level when supported by the model. |
response_format | string | No | — | Response image format. |
size | string | No | — | Target image size. Options / constraints: Use the values supported by the current model details page. |
quality | string | No | — | Generate quality levels. Options / constraints: Use only when the current provider channel supports this field. |
background | string | No | — | How the background should be treated, such as transparent or opaque. Options / constraints: Only used if supported by the current channel and output format. |
output_format | string | No | — | The requested image file format. Options / constraints: Use only when the current provider channel supports this field. |
extra_body.provider | object | No | — | Restricts or ranks candidate provider channels. Options / constraints: Use fields such as only, ignore, order, and sort according to the unified routing rules. |
JSON edits use Content-Type: application/json and require images at the root as an array. Multipart edits use Content-Type: multipart/form-data, multiple image files, and one optional mask file.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | The GPT Image model ID to call. |
prompt | string | Yes | — | Editing instructions. |
images | array | No | — | Root array of input images for a JSON edit. Options / constraints: Each item can be a string, {"image_url":"..."}, or {"b64_json":"..."}; maximum 16 images. |
image | file | No | — | Input image for multipart edit request. Options / constraints: Multiple image files can be submitted repeatedly; a maximum of 16 input images can be submitted. |
mask | file | No | — | Optional mask file for multipart edit requests. Options / constraints: JSON mask does not expose a fixed object structure. |
The image generation endpoint returns JSON. Available result fields depend on the model, provider channel, and requested output format.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
created | integer | No | — | The response creation time, usually as a Unix timestamp. |
data | array | No | — | The generated result list. Multi-image requests may return multiple results. |
data[].url | string | No | — | A temporary URL for the generated image. Options / constraints: Present only when the current model and provider channel return a URL. Copy the asset to your own storage promptly. |
data[].b64_json | string | No | — | The Base64-encoded image content. Options / constraints: Present only when the request and current provider channel support Base64 output. |
data[].revised_prompt | string | No | — | The prompt used or revised by the model. Options / constraints: Returned only by some models and provider channels. |
provider | string | No | — | Information about the service provider channel that actually carries the request. Options / constraints: Only non-streaming JSON responses may contain this field. |
The following fields are HTTP response headers, not JSON or SSE response body fields.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
X-Client-Request-Id | string | No | — | Echoed when supplied by the caller; not generated automatically when omitted. |
X-Upstream-Request-Id | string | No | — | Usually used for gateway request tracing; it is not the provider's original request ID. |
The model ID on this page comes from the confirmed Model Market snapshot. gpt-image-2 is the invocation identifier in the current Token Market catalog; do not infer that an identically named model exists in an upstream provider’s public catalog.
Use /images/generations for text generation; /images/edits for editing. The normal flow of GPT Image that supports SSE will end with data: [DONE] after the protocol termination event; when the flow is interrupted abnormally, it is not guaranteed to receive the termination event or data: [DONE].
In formal business, X-Client-Request-Id, X-Upstream-Request-Id, model and desensitized input metadata should be saved, and the resulting URL or Base64 data should be verified before entering into the database. provider may only appear in non-streaming JSON. Use limited retries for timeouts, throttling, and upstream failures to avoid automatic double billing.
The examples use placeholders. Replace them with a currently available model ID from the model details page, and keep your API Key in a server-side environment variable.
curl https://api.tokensmarket.ai/v1/images/generations \
-H "Authorization: Bearer $TOKEN_MARKET_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A cinematic paper-cut city at sunrise",
"size": "1024x1024",
"extra_body": {"provider": {"sort": ["latency"]}}
}'