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

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

Chọn model trước

  • Sử dụng model hình ảnh GPT như gpt-image-2 cho các request text-to-image với các tùy chọn điều khiển như output_format, quality, hoặc background
  • Sử dụng qwen-image khi bạn cần đúng nhà cung cấp đó, nhưng giữ n ở mức 1
  • Chọn một model ID hình ảnh hiện có từ trang Models

Request đầu tiên an toàn

  • Bắt đầu với gpt-image-2
  • Giữ size1024x1024
  • Model hình ảnh GPT trả về dữ liệu hình ảnh 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 kiểu hình ảnh được mã hóa cụ thể như jpeg
  • Kiểm tra hướng dẫn tạo hình ảnh của OpenAI trước khi thêm background, output_compression, hoặc streaming
  • Sử dụng một prompt và một hình ảnh đầu ra trước khi thêm batch generation hoặc tinh chỉnh phong cách

Chạy một tác vụ hình ảnh async

Sử dụng async: true cho các tác vụ hình ảnh chạy lâu khi client của bạn ưu tiên luồng gửi rồi polling thay vì giữ một kết nối HTTP mở. Request tạo sẽ trả về data.task_id. Polling 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 là tham số OpenAI. OpenAI ghi nhận streampartial_images cho các model hình ảnh GPT. Chế độ tác vụ bất đồng bộ của CometAPI trả về metadata tác vụ ở dạng JSON và sử dụng polling. Sử dụng chế độ tác vụ async với các model ID đã được ghi nhận sau: gpt-image-2doubao-seedream-4-0-250828. Với các model hình ảnh khác, hãy dùng tạo đồng bộ hoặc streaming trừ khi hỗ trợ tác vụ async được ghi nhận cho model đó. Khi một request bao gồm cả async: truestream: true, chế độ tác vụ async sẽ được ưu tiên. Request tạo sẽ trả về metadata tác vụ JSON thay vì một luồng SSE.

Hành vi request theo từng model

  • response_format chỉ áp dụng cho các model DALL·E; các model hình ảnh GPT trả về dữ liệu base64 và bỏ qua tham số này
  • Các model hình ảnh GPT sử dụng các tùy chọn điều khiển chỉ dành cho GPT như output_format, quality, background, và output_compression
  • Làm theo hướng dẫn tạo hình ảnh của OpenAI để biết các tùy chọn theo từng model mới nhất
  • qwen-image không hỗ trợ n > 1
Hình ảnh được tạo phải tuân thủ chính sách sử dụng của nhà cung cấp. Không gửi các 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. 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.

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.