curl --request POST \
--url https://api.apiyi.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-image-2-all",
"prompt": "Landscape 16:9 cinematic, old lighthouse at sunset"
}
'{
"data": [
{
"b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}
],
"created": 1778037127,
"usage": {
"input_tokens": 98,
"output_tokens": 1185,
"total_tokens": 1283
}
}Text-to-Image API Reference
gpt-image-2-all text-to-image API reference and interactive playground — generate images from text prompts, $0.03/image
curl --request POST \
--url https://api.apiyi.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-image-2-all",
"prompt": "Landscape 16:9 cinematic, old lighthouse at sunset"
}
'{
"data": [
{
"b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}
],
"created": 1778037127,
"usage": {
"input_tokens": 98,
"output_tokens": 1185,
"total_tokens": 1283
}
}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.
Bearer sk-xxx), type a prompt, and click send.response_format: "b64_json", so the response carries a multi-MB base64 string and the browser Playground may show 请求时发生错误: unable to complete request — the request actually succeeded; the browser just can’t render such a long base64 string.Recommended workflow:- Just want to view the image in the Playground? Pass
"response_format": "url"explicitly — the response is a single R2 link and renders fine. - Want base64? Copy the code sample below and run it locally — the code will decode and save the image to a file automatically.
size: the field has no effect — sendingautoor any concrete value does not error, but the value is silently ignored by the server. Dimensions are driven entirely by the prompt:- Prompt mentions a size/ratio (e.g., “Landscape 16:9”) → the model follows the prompt
- Prompt has no size hints → the same prompt yields varied dimensions across calls, like “drawing different cards” — useful for exploring multiple compositions
- For strict size locking, use
gpt-image-2-vip(supportsauto+ 30 explicit sizes)
n/quality/aspect_ratio: ❌ rejected. Sending these may trigger parameter validation errors.
prompt, e.g.:Landscape 16:9 cinematic, old lighthouse by the sea at duskPortrait 9:16 phone wallpaper, cyberpunk city rainy night1024×1024 square logo, minimalist cat line art
Code Examples
Python
import requests
API_KEY = "sk-your-api-key"
response = requests.post(
"https://api.apiyi.com/v1/images/generations",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"model": "gpt-image-2-all",
"prompt": "Landscape 16:9 cinematic, old lighthouse at sunset, photorealistic",
"response_format": "url"
},
timeout=300 # conservative — absorbs tail latency + image download time
).json()
image_url = response["data"][0]["url"]
print(image_url)
import requests
response = requests.post(
"https://api.apiyi.com/v1/images/generations",
headers={"Authorization": "Bearer sk-your-api-key"},
json={
"model": "gpt-image-2-all",
"prompt": "1024x1024 square logo, minimalist cat line art",
"response_format": "b64_json"
},
timeout=300 # conservative — absorbs tail latency + image download time
).json()
# Note: b64_json already includes the "data:image/png;base64," prefix — do not re-prepend
data_url = response["data"][0]["b64_json"]
cURL
curl -X POST "https://api.apiyi.com/v1/images/generations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2-all",
"prompt": "Landscape 16:9 cinematic, old lighthouse at sunset",
"response_format": "url"
}'
Node.js
const API_KEY = "sk-your-api-key";
const response = await fetch(
"https://api.apiyi.com/v1/images/generations",
{
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "gpt-image-2-all",
prompt: "1024x1024 square logo, minimalist cat line art",
response_format: "b64_json"
})
}
);
const data = await response.json();
// b64_json already includes the prefix — can be used directly as <img src>
document.getElementById("result").src = data.data[0].b64_json;
Browser JavaScript (Fetch)
const resp = await fetch('https://api.apiyi.com/v1/images/generations', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-your-api-key'
},
body: JSON.stringify({
model: 'gpt-image-2-all',
prompt: 'Portrait 9:16 phone wallpaper, cyberpunk city rainy night',
response_format: 'b64_json'
})
});
const { data } = await resp.json();
document.getElementById('result').src = data[0].b64_json;
Parameters Quick Reference
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Fixed value: gpt-image-2-all |
prompt | string | Yes | Prompt. Include size/ratio/style here |
size | string | No | Only auto is accepted (the same prompt yields varied dimensions). For strict size locking, use gpt-image-2-vip |
response_format | string | No | b64_json (default, returns base64 data URL) or url (returns R2 CDN link) |
response_format field supports dropdown selection.Response Format
data[0] returns either url or b64_json — never both (depends on response_format). This endpoint defaults to b64_json.
b64_json mode (default):
{
"data": [
{
"b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}
],
"created": 1778037127,
"usage": {
"input_tokens": 98,
"output_tokens": 1185,
"total_tokens": 1283
}
}
url mode (requires explicit "response_format": "url", R2 CDN globally accelerated):
{
"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 field already contains the data:image/png;base64, prefix. You can use it directly as <img src> or write it to a file. Do not manually prepend data:image/...;base64,. This differs from some legacy OpenAI-compatible models.Authorizations
API Key from the API易 Console
Body
Model name, fixed to gpt-image-2-all
gpt-image-2-all Prompt. Include size/ratio/style here, e.g., Landscape 16:9 cinematic, old lighthouse at sunset
"Landscape 16:9 cinematic, old lighthouse at sunset"
Response format. b64_json returns a base64 string already prefixed with a data URL header (default); url returns an R2 CDN link
b64_json, url Response
Image successfully generated. Defaults to base64 in data[0].b64_json — url is not returned in the same response.
Image generation response. data[0] returns either url or b64_json, never both (depends on response_format; this endpoint defaults to b64_json).
Was this page helpful?