跳转到主要内容
POST
This calling style is no longer recommended: use /v1/images/generations and /v1/images/edits instead — more stable, and the same code works with the official-relay gpt-image-2. The chat-style endpoint on this page still works, and remains useful for multi-turn iterative editing or passing online image URLs directly.
What the chat-style endpoint offers: one endpoint for both text-to-image and reference-image editing, accepting inline image URLs (CDN links or base64 data URLs) as references. The response is standard Chat Completions format, with the image returned as Markdown inside choices[0].message.content.If you want one codebase that works across both official-relay and reverse channels, use /v1/images/generations and /v1/images/edits (standard OpenAI Images API format).
Choosing a mode:
  • text-only messagestext-to-image
  • add image_url (URL or base64 data URL) to the user message → reference-image editing
  • to edit the previous image across turns → put the previous output’s URL into the image_url of a new user message (see Multi-turn editing)
Multi-turn editing does NOT work by keeping conversation history. This is a reverse model and only reads the image_url in the last user message as the base image; any image placed in assistant history (whether a plain-text URL or an image_url structure) is ignored. To edit the previous image you must pass it as the reference in a new user message — see Multi-turn editing.

Response format

The response is standard Chat Completions format, with the generated image as Markdown inside choices[0].message.content (an R2 CDN link by default):
Extracting the image: pull the Markdown link ![...](url) out of choices[0].message.content with a regex. In rare cases content holds a base64 data URL (![image](data:image/png;base64,...)), which the same regex captures — usable directly as an <img src>.
🖥️ Browser Playground limit (when the response carries base64): if content returns a long base64 blob, the response string can reach several MB and the Playground may show unable to complete request — the request actually succeeded; the browser just can’t render that much. Copy the code below and run it locally.

Code examples

The response is a standard Chat Completions structure with a choices field, so you can also use the OpenAI SDK directly (client.chat.completions.create(...)), read resp.choices[0].message.content for the Markdown, and extract the image URL. The examples below use plain requests / fetch.

Python (text-to-image)

Python (reference-image editing)

cURL (text-to-image)

cURL (reference-image editing)

Node.js (text-to-image)

Multi-turn editing

To keep editing on top of the previous image, do not rely on conversation history (images in assistant turns are ignored). The correct way: send the previous output’s URL again as the image_url of a new user message, together with the new instruction. To keep iterating, feed the latest output back in.
The “real conversational multi-turn via assistant history” pattern below does NOT work (the output won’t be based on the previous image) — do not use it:
Put https://.../cat.png into the image_url of a new user message (see the code above) for the edit to actually build on that image.
Equivalent approach: use the /v1/images/edits standard editing endpoint, uploading the previous output as the image field plus a new instruction — same iterative result. See Image Editing API.

Parameter reference

Multimodal content parts (when content is an array):

Why the chat-style endpoint

Two abilities, one endpoint

No switching between generations / edits — everything goes through one endpoint

Inline URLs

image_url accepts a CDN image link or base64 data URL directly — no multipart upload

Standard chat response

The response has choices, so the OpenAI SDK and Chat frontends work directly; the image is in the Markdown of message.content

Iterative editing

Feed the previous output as the reference in a new user turn to refine step by step (not conversational state memory)
If your code must support both official-relay and reverse channels, use /v1/images/generations and /v1/images/edits (standard OpenAI Images API format) — one codebase switches channels.

Model Overview

Capabilities, pricing, best practices

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

OpenAI Images API compatible endpoint

Image Editing API (/v1/images/edits)

multipart/form-data reference-image editing; multi-turn works the same way

Online generation

imagen.apiyi.com online testing

授权

Authorization
string
header
必填

API Key from the APIYI Console

请求体

application/json
model
enum<string>
默认值:gpt-image-2-all
必填

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

可用选项:
gpt-image-2-all
messages
object[]
必填

Conversation messages. The base image is taken only from the last user message's image_url.

stream
boolean
默认值:false

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

temperature
number
默认值:1

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

必填范围: 0 <= x <= 2

响应

Image generated. Standard Chat Completions format, with the image as Markdown inside choices[0].message.content.

Standard Chat Completions response. The generated image is returned as Markdown (![image](url)) inside choices[0].message.content — an R2 CDN link by default; in rare cases a base64 data URL.

id
string

Response ID

object
string
示例:

"chat.completion"

created
integer

Unix timestamp (seconds)

model
string
示例:

"gpt-image-2-all"

choices
object[]
usage
object

Token usage statistics