Creare un'immagine
Usa CometAPI POST /v1/images/generations per creare immagini con modelli di immagini compatibili con OpenAI e controlli specifici del modello.
Riferimento ufficiale
- Leggi la guida alla generazione di immagini di OpenAI prima di fare affidamento su controlli specifici del modello come
background,output_compression, streaming o future opzioni di GPT image - Usa il riferimento OpenAI Create image per l’elenco corrente dei parametri.
Scegli prima un modello
- Usa un modello GPT image come
gpt-image-2per richieste text-to-image con controlli comeoutput_format,qualityobackground - Usa
qwen-imagequando hai bisogno specificamente di quel provider, ma mantienina 1 - Scegli un model ID di immagini corrente dalla pagina Models
Prima richiesta sicura
- Inizia con
gpt-image-2 - Mantieni
sizea1024x1024 - I modelli GPT image restituiscono dati immagine codificati in base64 in
b64_json; decodificali per salvare il file immagine - Aggiungi
output_formatsolo quando hai bisogno di un tipo di immagine codificata specifico comejpeg - Controlla la guida alla generazione di immagini di OpenAI prima di aggiungere
background,output_compressiono 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
Usaasync: 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_formatsi 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,backgroundeoutput_compression - Segui la guida alla generazione di immagini di OpenAI per le opzioni specifiche del modello più recenti
qwen-imagenon supportan > 1
Autorizzazioni
Bearer token authentication. Use your CometAPI key.
Corpo
The image generation model to use. Choose a current model from the Models page.
Text description of the image you want to generate.
"A paper boat floating on calm water at sunrise."
Number of images to generate. Keep this at 1 for the broadest compatibility.
Quality setting for models that support it. See the OpenAI image generation guide for the latest model-specific values.
Requested output size. Supported values depend on the selected model. See the OpenAI image generation guide for the latest model-specific ranges.
"1024x1024"
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.
url, b64_json 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.
"jpeg"
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.
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.
- Completed image response
- Async task response
Unix timestamp for the completed generation.
Background mode returned by models that expose it.
Encoded image type returned by GPT image models.
Quality level returned by models that expose it.
Output size returned by models that expose it.
Token usage details when returned by the selected model.