Skip to main content
POST
Sử dụng route này để tạo hình ảnh từ văn bản với cấu trúc yêu cầu tương thích OpenAI trên CometAPI.

Tài liệu tham khảo chính thức

Chọn mô hình trước

  • Sử dụng một mô hình hình ảnh GPT như gpt-image-2 cho các yêu cầu chuyển văn bản thành hình ảnh với các tùy chọn điều khiển như output_format, quality hoặc background
  • Sử dụng gpt-image-2.5-sunburst hoặc gpt-image-2.5-flare khi bạn cần nền trong suốt hoặc các mức chất lượng xhighmax
  • Sử dụng qwen-image khi bạn cần chính nhà cung cấp đó, nhưng giữ n ở mức 1
  • Chọn một ID mô hình hình ảnh hiện tại từ trang Models

Yêu cầu đầu tiên an toàn

  • Bắt đầu với gpt-image-2
  • Giữ size1024x1024
  • Các mô hình hình ảnh GPT trả về dữ liệu hình ảnh được mã hóa base64 trong b64_json; hãy giải mã dữ liệu đó để lưu tệp hình ảnh
  • Chỉ thêm output_format khi bạn cần một loại hình ảnh được mã hóa cụ thể như jpeg
  • Hãy dùng một prompt và một hình ảnh đầu ra trước khi thêm tính năng tạo hàng loạt hoặc tinh chỉnh phong cách

Chạy tác vụ hình ảnh bất đồng bộ

Sử dụng async: true cho các tác vụ hình ảnh chạy lâu khi ứng dụng khách của bạn ưu tiên luồng gửi rồi thăm dò thay vì giữ một kết nối HTTP mở. Yêu cầu tạo trả về data.task_id. Thăm dò Truy xuất một tác vụ tạo hình ảnh cho đến khi data.statussuccess hoặc failure. Trường async là một phần mở rộng của CometAPI cho route này, không phải tham số OpenAI. OpenAI ghi nhận streampartial_images cho các mô hình hình ảnh GPT. Chế độ tác vụ bất đồng bộ của CometAPI trả về siêu dữ liệu tác vụ JSON và sử dụng cơ chế thăm dò. Sử dụng chế độ tác vụ bất đồng bộ với các ID mô hình đã được ghi nhận sau: gpt-image-2doubao-seedream-4-0-250828. Với các mô hình hình ảnh khác, hãy sử dụng tạo đồng bộ hoặc streaming, trừ khi mô hình đó có tài liệu về hỗ trợ tác vụ bất đồng bộ. Khi một yêu cầu bao gồm cả async: truestream: true, chế độ tác vụ bất đồng bộ được ưu tiên. Yêu cầu tạo trả về siêu dữ liệu tác vụ JSON thay vì luồng SSE.

Hành vi yêu cầu dành riêng cho mô hình

  • response_format chỉ áp dụng cho các mô hình DALL·E; các mô hình hình ảnh GPT trả về dữ liệu base64 và bỏ qua tham số này
  • Các mô hình hình ảnh GPT sử dụng các tùy chọn điều khiển GPT-only như output_format, quality, backgroundoutput_compression
  • quality chấp nhận low, medium, highauto trên các mô hình hình ảnh GPT; gpt-image-2.5-sunburstgpt-image-2.5-flare cũng chấp nhận xhighmax
  • output_compression áp dụng khi output_formatwebp hoặc jpeg; không có tác dụng với png
  • partial_images chỉ áp dụng khi streamtrue
  • Hãy xem hướng dẫn tạo hình ảnh của OpenAI để biết các tùy chọn dành riêng cho mô hình mới nhất
  • qwen-image không hỗ trợ n > 1

Tạo nền trong suốt

Đặt background thành transparent để tạo một chủ thể tách biệt không có nền tô. Tính năng này được hỗ trợ trên gpt-image-2.5-sunburstgpt-image-2.5-flare. Tính trong suốt cần định dạng đầu ra có kênh alpha. Đặt output_format thành png hoặc webp. JPEG không có kênh alpha, vì vậy yêu cầu trong suốt với output_format: "jpeg" sẽ bị từ chối. Phản hồi trả về dữ liệu hình ảnh base64 trong b64_json kèm kênh alpha. Giải mã dữ liệu đó để lưu tệp:
Đặt background thành opaque để buộc dùng nền đặc, hoặc auto để mô hình tự quyết định. Phản hồi lặp lại giá trị đã áp dụng trong trường background ở cấp cao nhất.
Hình ảnh được tạo phải tuân thủ các chính sách sử dụng của nhà cung cấp. Không gửi Prompt bất hợp pháp, bạo lực, khiêu dâm hoặc vi phạm bản quyền.

Ủy quyền

Authorization
string
header
bắt buộc

Bearer token authentication. Use your CometAPI key.

Nội dung

application/json
model
string
mặc định:gpt-image-2
bắt buộc

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

prompt
string
bắt buộc

Text description of the image you want to generate.

Ví dụ:

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

n
integer
mặc định: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.

Ví dụ:

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

Tùy chọn có sẵn:
transparent,
opaque,
auto
output_compression
integer
mặc định: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.

Phạm vi bắt buộc: 0 <= x <= 100
moderation
enum<string>
mặc định:auto

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

Tùy chọn có sẵn:
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.

Phạm vi bắt buộc: 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.

Ví dụ:

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

Tùy chọn có sẵn:
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.

Ví dụ:

"jpeg"

stream
boolean
mặc định: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
mặc định: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.

Phản hồi

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

created
integer
bắt buộc

Unix timestamp for the completed generation.

data
object[]
bắt buộc
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.

Lần sửa đổi cuối 11 tháng 9, 2026