Crea 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 di OpenAI alla generazione di immagini prima di fare affidamento su controlli specifici del modello come
background,output_compression, streaming o future opzioni per immagini GPT. - Usa il riferimento OpenAI Create image per l’elenco corrente dei parametri.
Scegli prima un modello
- Usa un modello di immagini GPT come
gpt-image-2per richieste text-to-image con controlli qualioutput_format,qualityobackground - Usa
gpt-image-2.5-sunburstogpt-image-2.5-flarequando ti servono sfondi trasparenti o i livelli di qualitàxhighemax - Usa
qwen-imagequando ti serve specificamente quel provider, ma mantienina 1 - Scegli un ID modello di immagini corrente dalla pagina Models
Prima richiesta sicura
- Inizia con
gpt-image-2 - Mantieni
sizesu1024x1024 - I modelli di immagini GPT restituiscono dati immagine codificati in base64 in
b64_json; decodificali per salvare il file immagine - Aggiungi
output_formatsolo quando ti serve un tipo di immagine codificata specifico, comejpeg - Usa un solo Prompt e una sola immagine di output prima di aggiungere la generazione in batch o la regolazione dello stile
Esegui un’attività immagine asincrona
Usaasync: true per processi di immagini di lunga durata quando il client preferisce un flusso di invio e polling anziché mantenere aperta una connessione HTTP. La richiesta di creazione restituisce data.task_id.
Esegui il polling di Recupera un’attività di generazione di immagini 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 di immagini GPT. La modalità di attività asincrona di CometAPI restituisce metadati dell’attività in JSON e usa il polling.
Usa la modalità di attività asincrona con questi ID modello 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 per le attività asincrone non sia documentato per quel modello.
Quando una richiesta include sia async: true sia stream: true, la modalità di attività asincrona ha la precedenza. La richiesta di creazione restituisce metadati dell’attività JSON anziché un flusso SSE.
Comportamento delle richieste specifico del modello
response_formatsi applica solo ai modelli DALL·E; i modelli di immagini GPT restituiscono dati base64 e lo ignorano- I modelli di immagini GPT usano i controlli GPT-only quali
output_format,quality,backgroundeoutput_compression qualityaccettalow,medium,higheautosui modelli di immagini GPT; anchegpt-image-2.5-sunburstegpt-image-2.5-flareaccettanoxhighemaxoutput_compressionsi applica quandooutput_formatèwebpojpeg; non ha effetto supngpartial_imagessi applica solo quandostreamètrue- Segui la guida di OpenAI alla generazione di immagini per le opzioni specifiche del modello più recenti
qwen-imagenon supportan > 1
Generare uno sfondo trasparente
Impostabackground su transparent per generare un soggetto isolato senza riempimento dello sfondo. Questa opzione è supportata su gpt-image-2.5-sunburst e gpt-image-2.5-flare.
La trasparenza richiede un formato di output con un canale alfa. Imposta output_format su png o webp. JPEG non dispone di un canale alfa, pertanto una richiesta di trasparenza con output_format: "jpeg" viene rifiutata.
La risposta restituisce dati dell’immagine in base64 in b64_json con un canale alfa. Decodificali per salvare il file:
background su opaque per forzare uno sfondo uniforme, oppure su auto per lasciare decidere al modello. La risposta riporta il valore applicato nel campo background di primo livello.
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. GPT image models accept low, medium, high, and auto. gpt-image-2.5-sunburst and gpt-image-2.5-flare also accept xhigh and max. dall-e-3 accepts standard and hd. See the OpenAI image generation guide for the latest model-specific values.
"low"
Background mode for the generated image. Set transparent to generate an isolated subject with no background fill; this requires output_format set to png or webp, and returns an error with jpeg. Set opaque for a solid background, or auto to let the model decide. Supported on gpt-image-2.5-sunburst and gpt-image-2.5-flare.
transparent, opaque, auto Compression level for the output image, from 0 to 100. Applies when output_format is webp or jpeg. Lower values produce smaller files with more compression artifacts.
0 <= x <= 100Content moderation level for GPT image models. low is less restrictive; auto is the default.
low, auto Number of partial images to emit while a streaming response is in progress, from 0 to 3. Each partial image arrives as an image_generation.partial_image event before the final image_generation.completed event. Applies when stream is true.
0 <= x <= 3Requested 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.