Przejdź do głównej treści
POST
Użyj tej trasy, aby tworzyć obrazy z tekstu przy użyciu formatów żądań zgodnych z OpenAI w CometAPI.

Oficjalna dokumentacja

Najpierw wybierz model

  • Użyj modelu obrazu GPT, takiego jak gpt-image-2, do żądań text-to-image z kontrolkami takimi jak output_format, quality lub background
  • Użyj gpt-image-2.5-sunburst lub gpt-image-2.5-flare, gdy potrzebujesz przezroczystego tła albo poziomów jakości xhigh i max
  • Użyj tego samego formatu żądania z innymi rodzinami modeli obrazowych, takimi jak Qwen-Image, Doubao Seedream lub Grok Imagine; zacznij od model i prompt
  • Wybierz aktualny identyfikator modelu obrazu na stronie modeli

Bezpieczne pierwsze żądanie

  • Zacznij od gpt-image-2
  • Ustaw size na 1024x1024
  • Modele obrazów GPT zwracają dane obrazu zakodowane w base64 w b64_json; zdekoduj je, aby zapisać plik obrazu
  • Dodaj output_format tylko wtedy, gdy potrzebujesz określonego typu zakodowanego obrazu, takiego jak jpeg
  • Użyj jednego Prompt i jednego obrazu wyjściowego, zanim dodasz generowanie wsadowe lub dostrajanie stylu

Uruchom asynchroniczne zadanie obrazu

Użyj async: true dla długotrwałych zadań obrazowych, gdy klient preferuje przepływ wysyłania i odpytywania zamiast utrzymywania jednego otwartego połączenia HTTP. Żądanie utworzenia zwraca data.task_id. Odpytuj zadanie generowania obrazu aż data.status będzie mieć wartość success lub failure. Pole async jest rozszerzeniem CometAPI dla tej trasy, a nie parametrem OpenAI. OpenAI dokumentuje stream i partial_images dla modeli obrazów GPT. Tryb zadań asynchronicznych CometAPI zwraca metadane zadań JSON i używa odpytywania. Użyj trybu zadań asynchronicznych z tymi udokumentowanymi identyfikatorami modeli: gpt-image-2 i doubao-seedream-4-0-250828. W przypadku innych modeli obrazowych użyj generowania synchronicznego lub streaming, chyba że dla danego modelu udokumentowano obsługę zadań asynchronicznych. Gdy żądanie zawiera zarówno async: true, jak i stream: true, tryb zadań asynchronicznych ma pierwszeństwo. Żądanie utworzenia zwraca metadane zadania JSON zamiast strumienia SSE.

Zachowanie żądań specyficzne dla modelu

  • response_format ma zastosowanie tylko do modeli DALL·E; modele obrazów GPT zwracają dane base64 i je ignorują
  • Modele obrazów GPT używają kontrolek GPT-only, takich jak output_format, quality, background i output_compression
  • quality akceptuje low, medium, high i auto w modelach obrazów GPT; gpt-image-2.5-sunburst i gpt-image-2.5-flare akceptują również xhigh i max
  • output_compression ma zastosowanie, gdy output_format ma wartość webp lub jpeg; nie ma wpływu na png
  • partial_images ma zastosowanie tylko wtedy, gdy stream ma wartość true
  • Najnowsze opcje specyficzne dla modelu znajdziesz w przewodniku OpenAI dotyczącym generowania obrazów
  • Inne rodziny modeli obrazowych mogą zwracać obraz w url zamiast w b64_json; odczytaj pole zawarte w każdym elemencie wyniku

Wygeneruj przezroczyste tło

Ustaw background na transparent, aby wygenerować wyizolowany obiekt bez wypełnienia tła. Jest to obsługiwane w gpt-image-2.5-sunburst i gpt-image-2.5-flare. Przezroczystość wymaga formatu wyjściowego z kanałem alfa. Ustaw output_format na png lub webp. Format JPEG nie ma kanału alfa, więc żądanie przezroczystości z wartością output_format: "jpeg" zostanie odrzucone. Odpowiedź zwraca dane obrazu base64 w b64_json z kanałem alfa. Zdekoduj je, aby zapisać plik:
Ustaw background na opaque, aby wymusić jednolite tło, lub na auto, aby pozwolić modelowi zdecydować. Odpowiedź zwraca zastosowaną wartość w polu background najwyższego poziomu.
Wygenerowane obrazy muszą być zgodne z zasadami użytkowania dostawcy. Nie wysyłaj Promptów nielegalnych, zawierających przemoc, pornograficznych ani naruszających prawa autorskie.

Autoryzacje

Authorization
string
header
wymagane

Bearer token authentication. Use your CometAPI key.

Treść

application/json
model
string
domyślnie:gpt-image-2
wymagane

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

prompt
string
wymagane

Text description of the image you want to generate.

Przykład:

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

n
integer
domyślnie:1

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

quality
string

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.

Przykład:

"low"

background
enum<string>

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.

Dostępne opcje:
transparent,
opaque,
auto
output_compression
integer
domyślnie:100

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.

Wymagany zakres: 0 <= x <= 100
moderation
enum<string>
domyślnie:auto

Content moderation level for GPT image models. low is less restrictive; auto is the default.

Dostępne opcje:
low,
auto
partial_images
integer

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.

Wymagany zakres: 0 <= x <= 3
size
string

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

Przykład:

"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.

Dostępne opcje:
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.

Przykład:

"jpeg"

stream
boolean
domyślnie: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
domyślnie: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.

Odpowiedź

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

created
integer
wymagane

Unix timestamp for the completed generation.

data
object[]
wymagane
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.

Ostatnia modyfikacja 29 października 2026