Chuyển đến nội dung chính
POST
/
v1
/
images
/
generations
curl --request POST \
  --url https://api.cometapi.com/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "gpt-image-2",
  "prompt": "A paper boat floating on calm water at sunrise."
}
'
{
  "created": 1776841943,
  "background": "opaque",
  "output_format": "jpeg",
  "quality": "low",
  "size": "1024x1024",
  "usage": {
    "input_tokens": 16,
    "input_tokens_details": {
      "image_tokens": 0,
      "text_tokens": 16
    },
    "output_tokens": 208,
    "total_tokens": 224
  },
  "data": [
    {
      "b64_json": "<base64-image-data>"
    }
  ]
}

Documentation Index

Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt

Use this file to discover all available pages before exploring further.

Sử dụng route này để tạo ảnh từ văn bản với cấu trúc 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

  • Dùng dall-e-3 khi bạn muốn có request đầu tiên đơn giản với response_format
  • Dùng model ảnh GPT khi bạn cần các tùy chọn chỉ có ở GPT như output_format, quality hoặc background
  • Dùng qwen-image khi bạn cần đúng provider đó, nhưng giữ n ở mức 1

Request đầu tiên an toàn

  • Bắt đầu với dall-e-3
  • Giữ size1024x1024
  • Đặt response_format: "url" nếu bạn muốn phản hồi JSON nhỏ gọn và một URL tải xuống tạm thời
  • Sử dụng ví dụ request GPT đã được xác thực trong tài liệu tham chiếu API nếu bạn cần các tham số của model ảnh GPT
  • Chỉ thêm output_format khi bạn cần một kiểu ảnh được mã hóa cụ thể như jpeg
  • Kiểm tra hướng dẫn tạo ảnh của OpenAI trước khi bạn thêm background, output_compression hoặc streaming
  • Dùng một Prompt và một ảnh đầu ra trước khi bạn thêm tạo hàng loạt hoặc tinh chỉnh phong cách

Hành vi request theo từng model

  • response_format áp dụng cho dall-e-2dall-e-3
  • Các model ảnh GPT dùng các tùy chọn chỉ có ở GPT như output_format, quality, backgroundoutput_compression
  • Làm theo hướng dẫn tạo ảnh của OpenAI để biết các tùy chọn mới nhất theo từng model
  • qwen-image không hỗ trợ n > 1
Ảnh được tạo phải tuân thủ chính sách sử dụng của provider. 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:dall-e-3
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"

Phản hồi

200 - application/json

Image generation result.

created
integer
bắt buộc

Unix timestamp for the completed generation.

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