Skip to main content
POST
Usa questa route per creare immagini da testo con request shape compatibili con OpenAI su CometAPI.

Riferimento ufficiale

Scegli prima un modello

  • Usa un modello GPT image come gpt-image-2 per richieste text-to-image con controlli come output_format, quality o background
  • Usa qwen-image quando hai bisogno specificamente di quel provider, ma mantieni n a 1
  • Scegli un model ID di immagini corrente dalla pagina Models

Prima richiesta sicura

  • Inizia con gpt-image-2
  • Mantieni size a 1024x1024
  • I modelli GPT image restituiscono dati immagine codificati in base64 in b64_json; decodificali per salvare il file immagine
  • Aggiungi output_format solo quando hai bisogno di un tipo di immagine codificata specifico come jpeg
  • Controlla la guida alla generazione di immagini di OpenAI prima di aggiungere background, output_compression o streaming
  • Usa un prompt e un’immagine di output prima di aggiungere la generazione batch o la regolazione dello stile

Eseguire un task immagine asincrono

Usa async: true per job di immagini di lunga durata quando il tuo client preferisce un flusso submit-and-poll invece di mantenere aperta una connessione HTTP. La request di creazione restituisce data.task_id. Interroga Retrieve an image generation task finché data.status non è success o failure. Il campo async è un’estensione CometAPI per questa route, non un parametro OpenAI. OpenAI documenta stream e partial_images per i modelli GPT image. La modalità task asincrona di CometAPI restituisce metadati del task in JSON e usa il polling. Usa la modalità task asincrona con questi model ID documentati: gpt-image-2 e doubao-seedream-4-0-250828. Per altri modelli di immagini, usa la generazione sincrona o lo streaming a meno che il supporto ai task asincroni non sia documentato per quel modello. Quando una request include sia async: true sia stream: true, la modalità task asincrona ha la precedenza. La request di creazione restituisce metadati del task in JSON invece di uno stream SSE.

Comportamento della request specifico del modello

  • response_format si applica solo ai modelli DALL·E; i modelli GPT image restituiscono dati base64 e lo ignorano
  • I modelli GPT image usano controlli solo GPT come output_format, quality, background e output_compression
  • Segui la guida alla generazione di immagini di OpenAI per le opzioni specifiche del modello più recenti
  • qwen-image non supporta n > 1
Le immagini generate devono essere conformi alle policy di utilizzo del provider. Non inviare prompt illegali, violenti, pornografici o che violano il copyright.

Autorizzazioni

Authorization
string
header
obbligatorio

Bearer token authentication. Use your CometAPI key.

Corpo

application/json
model
string
predefinito:gpt-image-2
obbligatorio

The image generation model to use. Choose a current model from the Models page.

prompt
string
obbligatorio

Text description of the image you want to generate.

Esempio:

"A paper boat floating on calm water at sunrise."

n
integer
predefinito:1

Number of images to generate. Keep this at 1 for the broadest compatibility.

quality
string

Quality setting for models that support it. See the OpenAI image generation guide for the latest model-specific values.

size
string

Requested output size. Supported values depend on the selected model. See the OpenAI image generation guide for the latest model-specific ranges.

Esempio:

"1024x1024"

response_format
enum<string>

The response container for dall-e-2 and dall-e-3. This parameter is not supported for GPT image models, which return base64-encoded image data.

Opzioni disponibili:
url,
b64_json
output_format
string

The encoded image type for GPT image model results, such as png, jpeg, or webp. See the OpenAI image generation guide for current GPT image output controls.

Esempio:

"jpeg"

stream
boolean
predefinito:false

Set this to true to receive server-sent image generation events instead of waiting for the completed JSON response. Streaming responses use text/event-stream and can include final events such as image_generation.completed. When stream and async are both true, async task mode takes precedence and the create request returns JSON instead of a streaming image response.

async
boolean
predefinito:false

CometAPI asynchronous task mode. Set this to true to return immediately with data.task_id, then poll GET /v1/images/generations/{task_id} for the final image data. Documented model IDs for this mode: gpt-image-2 and doubao-seedream-4-0-250828. This is a CometAPI extension, not an OpenAI parameter. When async and stream are both true, async takes precedence and returns JSON task metadata instead of an SSE stream.

Risposta

Image generation result. Synchronous requests return completed image data. Async requests return a task response with data.task_id.

created
integer
obbligatorio

Unix timestamp for the completed generation.

data
object[]
obbligatorio
background
string

Background mode returned by models that expose it.

output_format
string

Encoded image type returned by GPT image models.

quality
string

Quality level returned by models that expose it.

size
string

Output size returned by models that expose it.

usage
object

Token usage details when returned by the selected model.