跳转到主要内容

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.

通过选择与您的工作流程匹配的请求格式,使用 CometAPI 图像模型文档。OpenAI 兼容的图像端点覆盖常见的生成和编辑流程;特定提供商页面则覆盖基于任务的图像系统。

选择一个图像 API

Image Generations

使用 OpenAI 兼容的请求生成图像。

Image Editing

使用 OpenAI 兼容的请求编辑图像。

Gemini image generation

使用 Gemini 格式生成或编辑图像。

Midjourney quick start

提交并轮询 Midjourney 图像任务。

Flux Generate Image

通过 CometAPI 生成 Flux 图像。

Bria Generate Image

使用 Bria 图像生成工具。

生成图像

Models pagemodel directory 中选择一个支持图像的 model ID。下面的示例调用 OpenAI 兼容的 Image Generations API。
这些示例使用占位符 your-image-model-id。在运行请求之前,请将其替换为 Models pagemodel directory 中可用的图像 model ID。
打开 Image Generations 以使用 playground 和端点 schema。
import os
import requests

response = requests.post(
    "https://api.cometapi.com/v1/images/generations",
    headers={
        "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
        "Content-Type": "application/json",
    },
    json={
        "model": "your-image-model-id",
        "prompt": "A clean product photo of a glass teapot on a white table",
        "size": "1024x1024",
    },
    timeout=120,
)

response.raise_for_status()
result = response.json()
print(result["data"][0].keys())

响应示例

成功响应可能如下所示。根据所选模型,每个条目可以包含 base64 图像或结果 URL:
{
  "created": 1779872000,
  "background": "opaque",
  "data": [
    {
      "b64_json": "iVBORw0KGgo..."
    }
  ],
  "output_format": "png",
  "quality": "low",
  "size": "1024x1024",
  "usage": {
    "input_tokens": 19,
    "input_tokens_details": {
      "image_tokens": 0,
      "text_tokens": 19
    },
    "output_tokens": 196,
    "output_tokens_details": {
      "image_tokens": 196,
      "text_tokens": 0
    },
    "total_tokens": 215
  }
}

示例 model 记录

这个示例模型目录响应展示了 /api/models 封装和一种图像 model 记录的形状。它不是完整的模型列表。
cURL
curl https://api.cometapi.com/api/models
{
  "success": true,
  "page": 1,
  "page_size": 20,
  "total": 302,
  "data": [
    {
      "created": 1776391310,
      "id": "your-image-model-id",
      "code": "your-image-model-id",
      "provider": "ExampleProvider",
      "provider_code": "example",
      "name": "Example image model",
      "model_type": "image",
      "features": [
        "text-to-image"
      ],
      "endpoints": "{\n  \"openai-image\": {\n    \"path\": \"/v1/images/generations\",\n    \"method\": \"POST\"\n  }\n}",
      "pricing": {
        "currency": "USD / M Tokens",
        "input": 4,
        "output": 24,
        "per_request": null,
        "per_second": null
      }
    }
  ]
}

常见错误

Models page 中选择一个支持图像的 model。
使用所选图像端点接受的尺寸。
在提供商链接过期之前下载生成的资源。
使用图像 URL 或更小的文件,而不是大型 base64 负载。
同时检查 b64_jsonurl 字段,因为输出结构可能因 model 而异。

错误代码和重试策略

在修复 Prompt、尺寸或图像输入之前不要重试。
在 API key 存在且有效之前不要重试。
重试前检查基础 URL、路径和 model ID。
重试前减小上传大小。
使用指数退避重试,并降低并发。
对临时的提供商或服务错误使用退避重试。
有关实现模式,请参阅 Error codes and retry strategyRate limits and concurrency

定价和 model 目录

Models page

阅读 CometAPI 如何在文档中公开 model ID。

Model directory

浏览 model 可用性和能力。

Pricing

在调用 model 之前查看定价。
Last modified on May 28, 2026