Skip to main content
POST
/
v1
/
chat
/
completions
curl --request POST \
  --url https://api.apiyi.com/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "gpt-image-2-vip",
  "messages": [
    {
      "role": "user",
      "content": "Landscape 16:9 cinematic, old lighthouse at sunset, photorealistic"
    }
  ]
}
'
{
  "data": [
    {
      "url": "https://r2cdn.copilotbase.com/r2cdn2/0e82148a-bec0-4b42-bbca-117c6b42581b.png"
    }
  ],
  "created": 1778037331,
  "usage": {
    "input_tokens": 30,
    "output_tokens": 2074,
    "total_tokens": 2104
  }
}

Documentation Index

Fetch the complete documentation index at: https://docs.apiyi.com/llms.txt

Use this file to discover all available pages before exploring further.

Chat endpoint highlights: one endpoint handles both text-to-image and reference-image editing, accepts online image URLs (CDN links or base64 data URLs) directly, and supports natural multi-turn iteration. Enter your API Key in the Playground on the right and pick an example from the dropdown (text-to-image / reference editing / multi-turn).If you want one codebase that hits both the official and reverse channels, prefer /v1/images/generations and /v1/images/edits (OpenAI Images API standard format).
Mode selection:
  • Text-only messagestext-to-image
  • Add image_url (URL or base64 data URL) → reference-image edit
  • Keep prior assistant messages and continue → multi-turn iteration
Difference vs gpt-image-2-all: identical call format — just swap model to gpt-image-2-vip. This endpoint additionally accepts a top-level size field to lock dimensions (30-bucket set, same as /v1/images/generations).size is optional: pass it to lock the output dimensions; omit it to let the prompt drive sizing (same as -all).
🖥️ Browser Playground limitation (when response contains base64)This endpoint defaults to an R2 CDN URL (data[0].url) and the Playground displays it fine. In rare cases the response carries base64 (data[0].b64_json), or you pass a large base64 input image via image_url, in which case the response string can be multi-MB and the browser Playground may show 请求时发生错误: unable to complete requestthe request actually succeeded; the browser just can’t display such a long string.Recommended workflow: when you see this prompt, copy the code samples below to your local machine — your code can read the result from data[0].url or data[0].b64_json (only one of the two appears, never both).

Code Examples

Python (text-to-image)

import requests

API_KEY = "sk-your-api-key"

response = requests.post(
    "https://api.apiyi.com/v1/chat/completions",
    headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},
    json={
        "model": "gpt-image-2-vip",
        "size": "2048x1152",  # Optional; omit to let the prompt drive sizing
        "messages": [
            {"role": "user", "content": "Cinematic landscape 16:9, old lighthouse by the sea at dusk, photorealistic"}
        ]
    },
    timeout=300
).json()

# Defaults to url; if you switch to b64_json mode, read response["data"][0]["b64_json"]
print(response["data"][0]["url"])

Python (reference-image edit)

import requests
import base64

API_KEY = "sk-your-api-key"

# HTTPS URL or base64 data URL — both work
with open("photo.png", "rb") as f:
    data_url = "data:image/png;base64," + base64.b64encode(f.read()).decode()

response = requests.post(
    "https://api.apiyi.com/v1/chat/completions",
    headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},
    json={
        "model": "gpt-image-2-vip",
        "size": "2048x2048",  # Optional; omit to let the prompt drive sizing
        "messages": [
            {
                "role": "user",
                "content": [
                    {"type": "text", "text": "Convert this image into watercolor style"},
                    {"type": "image_url", "image_url": {"url": data_url}}
                ]
            }
        ]
    },
    timeout=300
).json()

# Defaults to url; if you switch to b64_json mode, read response["data"][0]["b64_json"]
print(response["data"][0]["url"])

cURL (text-to-image)

curl -X POST "https://api.apiyi.com/v1/chat/completions" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2-vip",
    "size": "2048x1152",
    "messages": [
      {"role": "user", "content": "Cyberpunk rainy night street, 16:9, neon sign reading Hello World"}
    ]
  }'

cURL (reference-image edit)

curl -X POST "https://api.apiyi.com/v1/chat/completions" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2-vip",
    "messages": [
      {
        "role": "user",
        "content": [
          { "type": "text", "text": "Convert this image into watercolor style" },
          { "type": "image_url", "image_url": { "url": "https://example.com/photo.png" } }
        ]
      }
    ]
  }'

Node.js (text-to-image)

const API_KEY = "sk-your-api-key";

const response = await fetch("https://api.apiyi.com/v1/chat/completions", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${API_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "gpt-image-2-vip",
    messages: [
      { role: "user", content: "1024x1024 square logo, minimalist cat line art" }
    ]
  })
});

const data = await response.json();
// Defaults to url; if you switch to b64_json mode, read data.data[0].b64_json
console.log(data.data[0].url);
About the OpenAI SDK: The request format is OpenAI Chat Completions compatible, but the response format is {data: [{url|b64_json}], created, usage} — there is no choices field. Calling client.chat.completions.create(...) will fail to parse the response. Use the requests / fetch snippets above to read the raw JSON instead.

Parameters

ParameterTypeRequiredDescription
modelstringYesFixed at gpt-image-2-vip
messagesarrayYesConversation array; supports system / user / assistant roles
messages[].contentstring | arrayYesPlain string (text-to-image) or multimodal array (with reference image)
sizestringNoOutput dimensions (30-bucket set), e.g. 2048x1152, 3840x2160. Omit to let the prompt drive sizing. See model overview for the full list
streambooleanNoStreaming. This model is one-shot; keep false.
Multimodal content fragments (when content is an array):
FieldTypeRequiredDescription
typeenumYestext or image_url
textstringConditionalRequired when type=text
image_url.urlstringConditionalRequired when type=image_url. Accepts https://... or data:image/png;base64,...
See the right-side Playground for full field details. The “Example” dropdown switches between text-to-image / reference editing / multi-turn iteration.

Response Format

The chat endpoint responds with {data: [{url|b64_json}], created, usage}. data[0] returns either url or b64_json, never both. This endpoint defaults to url. Default url output:
{
  "data": [
    {
      "url": "https://r2cdn.copilotbase.com/r2cdn2/0e82148a-bec0-4b42-bbca-117c6b42581b.png"
    }
  ],
  "created": 1778037331,
  "usage": {
    "input_tokens": 30,
    "output_tokens": 2074,
    "total_tokens": 2104
  }
}
b64_json output (rare):
{
  "data": [
    {
      "b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ],
  "created": 1778037127,
  "usage": {
    "input_tokens": 98,
    "output_tokens": 1185,
    "total_tokens": 1283
  }
}
Parsing tip: read data[0].url first; if it’s empty, fall back to data[0].b64_json. The b64_json value already includes the data:image/png;base64, prefix and can be used directly as <img src>.

Why the Chat Endpoint

One endpoint, two abilities

No need to switch between generations / edits — all flows hit the same endpoint.

Online URL inputs

image_url accepts CDN URLs or base64 data URLs directly — no multipart upload needed.

Native multi-turn

Keep prior assistant messages to continue refining — same logic as ChatGPT.

Best SDK coverage

Works with the official OpenAI SDK, LangChain, and most Chat frontends out of the box.
Strict size locking: pass the top-level size field (e.g. 2048x1152, 3840x2160) to lock the output to one of the 30 buckets. If you prefer the OpenAI Images API standard format, you can also use the text-to-image endpoint (/v1/images/generations).

Model Overview (full size table)

Complete 30-size table, pricing, technical specs

Text-to-Image API (/v1/images/generations)

OpenAI Images API compatible endpoint, pass size to lock dimensions

Image Editing API (/v1/images/edits)

multipart/form-data upload with reference images

Sister model gpt-image-2-all

Same call format when you don’t need locked size — faster output

Authorizations

Authorization
string
header
required

API Key from the API易 Console

Body

application/json
model
enum<string>
default:gpt-image-2-vip
required

Model name, fixed to gpt-image-2-vip

Available options:
gpt-image-2-vip
messages
object[]
required

Conversation messages. Supports multi-turn and multimodal content.

size
enum<string>

Output dimensions. Optional. Pass auto to let the model decide (vip tends to converge on a relatively fixed size for a given prompt; with reference images, the output follows the aspect ratio of whichever reference image the prompt names as the edit target — not necessarily the first one in multi-image scenarios), or pick one of the 30 supported sizes (10 ratios × 1K Fast / 2K Recommended / 4K Detail) to lock it strictly. Omit to let the prompt drive the output size. Format: width x height with a lowercase ASCII x, e.g. 2048x1360, 3840x2160. Flat $0.03/image across all buckets.

Available options:
auto,
1280x1280,
848x1280,
1280x848,
960x1280,
1280x960,
1024x1280,
1280x1024,
720x1280,
1280x720,
1280x544,
2048x2048,
1360x2048,
2048x1360,
1536x2048,
2048x1536,
1632x2048,
2048x1632,
1152x2048,
2048x1152,
2048x864,
2880x2880,
2336x3520,
3520x2336,
2480x3312,
3312x2480,
2560x3216,
3216x2560,
2160x3840,
3840x2160,
3840x1632
Example:

"2048x1152"

stream
boolean
default:false

Whether to stream the response. This model returns one-shot — keep false. Playground does not support streaming preview.

temperature
number
default:1

Sampling temperature (minor effect on image generation — default is fine)

Required range: 0 <= x <= 2

Response

Image generated. Defaults to an R2 CDN URL in data[0].urlb64_json is not returned in the same response.

Response shape for the chat endpoint. data[0] returns either url or b64_json, never both. This endpoint defaults to url.

data
object[]

Generated results (this model returns 1 image per call)

created
integer

Unix timestamp (seconds)

usage
object

Token usage statistics