BLACK FRIDAYUntil Dec 8 (Tue) 23:59 JSTUntil Dec 8

DocsGPT Image 2 (Low) API usage and code examples

GPT Image 2 (Low) API usage and code examples

Base URL, authentication, endpoints, and code examples for calling GPT Image 2 (Low) (model ID: gpt-image-2-low) through the API.

Model details

Model IDgpt-image-2-low
ProviderOpenAI
TypeImage
StatusAvailable
Processing regionGlobal
PricingSee the model page

Base URL and authentication

FormatBase URLKey header
OpenAIhttps://token.echohub.io/v1Authorization: Bearer

Create an API key in the console and put it in the ECHO_API_KEY environment variable.

Endpoints

Method and pathWhat it does
POST /v1/images/generationsGenerate images

Call examples

Generates one image and saves it as image.png.

curl -o response.json https://token.echohub.io/v1/images/generations \
  -H "Authorization: Bearer $ECHO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2-low",
    "prompt": "A Shiba Inu walking on the beach at dusk",
    "n": 1,
    "size": "1024x1024",
    "quality": "low"
  }'

# Save the image as image.png (works for both b64_json and url; if the request failed, response.json holds the error)
python3 -c "import json, base64, urllib.request; d = json.load(open('response.json'))['data'][0]; open('image.png', 'wb').write(base64.b64decode(d['b64_json'])) if d.get('b64_json') else urllib.request.urlretrieve(d['url'], 'image.png')"

Rules for this model

  • Always set quality to low (leaving it out, or a quality that differs from the model name, returns HTTP 400)
  • size must be 1024x1024, 1536x1024 or 1024x1536
  • n must be 1
  • By default the image comes back as b64_json. Set "response_format": "url" to get the image URL (url) instead
  • stream, partial_images, input_fidelity and image editing (/v1/images/edits) cannot be used

Related docs