Skip to main content
POST
/
v1
/
images
/
generations
Text-to-Image: generate an image from a text prompt
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",
  "response_format": "url"
}
'
{
  "data": [
    {
      "url": "https://r2cdn.copilotbase.com/r2cdn2/00aaa9fb-756c-4119-a4a0-4a44fc75152b.png",
      "b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ]
}
The interactive Playground on the right supports direct online testing. Enter your API Key in the Authorization field (format: Bearer sk-xxx), type a prompt, and click send.
Scope: This page is for text-to-image generation. Just enter a prompt — no image upload required. To edit or fuse existing images, use the Image Editing endpoint.
⚠️ Unsupported ParametersThis model does not accept size, n, quality, aspect_ratio, etc. Sending these may trigger parameter validation errors.Write size and ratio directly into the prompt, e.g.:
  • Landscape 16:9 cinematic, old lighthouse by the sea at dusk
  • Portrait 9:16 phone wallpaper, cyberpunk city rainy night
  • 1024×1024 square logo, minimalist cat line art
Put size descriptions at the front of the prompt for better adherence.

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=120
).json()

image_url = response["data"][0]["url"]
print(image_url)
b64_json mode (get a ready-to-render data 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=120
).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

ParameterTypeRequiredDescription
modelstringYesFixed value: gpt-image-2-all
promptstringYesPrompt. Include size/ratio/style here
response_formatstringNourl (default, R2 CDN link) or b64_json
Detailed parameter constraints and allowed values are shown in the right-hand Playground. The response_format field supports dropdown selection.

Response Format

url mode (default, R2 CDN global acceleration):
{
    "data": [
        {
            "url": "https://r2cdn.copilotbase.com/r2cdn2/00aaa9fb-756c-4119-a4a0-4a44fc75152b.png"
        }
    ]
}
b64_json mode (requires explicit "response_format": "b64_json"):
{
    "data": [
        {
            "b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
        }
    ]
}
Compatibility note: The 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

Authorization
string
header
required

API Key from the API易 Console

Body

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

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

Available options:
gpt-image-2-all
prompt
string
required

Prompt. Include size/ratio/style here, e.g., Landscape 16:9 cinematic, old lighthouse at sunset

Example:

"Landscape 16:9 cinematic, old lighthouse at sunset"

response_format
enum<string>
default:url

Response format. url returns an R2 CDN link (default); b64_json returns a base64 string already prefixed with a data URL header

Available options:
url,
b64_json

Response

Image successfully generated

data
object[]

Result array (this model returns 1 image per call)