Skip to content

Migrating from OpenAI

Most code that calls the OpenAI Images API works after two changes. Then review the behaviour notes below.

1. Change the base URL and key

from openai import OpenAI

client = OpenAI(
    api_key="sk-...",                         # your YexAPI key
    base_url="https://api.yexapi.com/v1",     # was https://api.openai.com/v1
)
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "sk-...",                           // your YexAPI key
  baseURL: "https://api.yexapi.com/v1",       // was https://api.openai.com/v1
});
export OPENAI_API_KEY="sk-..."
export OPENAI_BASE_URL="https://api.yexapi.com/v1"

2. Use the model name gpt-image-2

client.images.generate(model="gpt-image-2", prompt="...", size="1024x1024")

Differences to check

Topic YexAPI behaviour
Endpoints Images only: /v1/images/generations, /v1/images/edits, plus the async endpoints.
n Only 1. Higher values return 400. See n.
size Any WIDTHxHEIGHT, an aspect ratio such as 16:9, or auto, plus optional resolution. See Size.
Output pixels Chosen by the model; may differ from the request. See Size.
quality, style, moderation, output_format, output_compression Accepted but ignored. Output is PNG.
response_format url (default) and b64_json are both supported; b64_json responses also include the URL.
Edits JSON with image URLs only; no multipart upload, no mask. See Image edits.
Streaming Not supported.
Image URLs Hosted on api.yexapi.com, valid for 30 days.
Billing Flat price per image by resolution tier; failed generations are refunded. See Billing.

Checklist

  • [ ] Base URL is https://api.yexapi.com/v1
  • [ ] Using a YexAPI key (sk-...)
  • [ ] model is gpt-image-2
  • [ ] n is 1 or not sent
  • [ ] Edits use public image URLs instead of file uploads
  • [ ] HTTP timeout is at least 120 s, or you use the async endpoint