Skip to main content

What you will build

You will call POST /v1/images/generations, generate one image with a GPT image model, decode the returned b64_json, and save it as an image file.

Prerequisites

  • A CometAPI API key stored in COMETAPI_KEY
  • Python 3.10+ or Node.js 18+ for file-saving examples
  • A server-side environment. Do not call image generation from public frontend code with a secret key.

API key, base URL, authentication

Use the OpenAI-compatible image endpoint:
Authenticate with a Bearer token:

Code examples

Use the tabs below for copyable examples in cURL, Python, and Node.js.

Flow explanation

GPT image generation returns the completed response in one request. GPT image models return base64 image data in data[0].b64_json. Decode that value and write the bytes to a file that matches output_format. If you need URL output, check whether the selected model supports URL responses. GPT image models use base64 output in the maintained reference example.

Common parameters

Troubleshooting / FAQ

Confirm you decoded b64_json as base64 bytes and saved the file extension that matches output_format.
Image parameters vary by model. Start with the minimal reference example, then add one optional field at a time.
Use b64_json for GPT image models. URL output is model-specific.

Next steps

Last modified on June 30, 2026