> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aitoearn.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI 图像生成

> 接口说明：OpenAI Images API `/v1/images/generations` 的兼容端点（文生图）。请求、响应与错误格式完全遵循 OpenAI 规范：返回 OpenAI 原始 `ImagesResponse`，不使用 AiToEarn 通用响应包裹；图片链接为上游原始返回，不做转存。鉴权使用 `Authorization: Bearer <API Key>`（OpenAI SDK 默认携带），已有 OpenAI SDK 或生态工具只需替换 baseURL 与 API Key 即可接入，按 AiToEarn 积分计费。

模型取值来自[「图像生成模型」](/api-reference/get-api-ai-models-image-generation)接口返回的 `data[n].name`。如需 AiToEarn 通用响应格式（`code === 0`）与转存后的稳定图片链接，请改用[「生成图像」](/api-reference/post-api-ai-image-generate)接口。



## OpenAPI

````yaml /openapi/zh/aitoearn.openapi.json post /api/ai/images/generations
openapi: 3.0.1
info:
  title: AiToEarn 开放平台 API
  description: AiToEarn 开放平台 API，支持在中国站与国际站之间切换调试。业务是否成功以响应体 code === 0 为准。
  version: 1.0.0
  contact: {}
servers:
  - url: https://aitoearn.cn
    description: 中国站
  - url: https://aitoearn.ai
    description: 国际站
security: []
tags:
  - name: AI 服务
  - name: AI 服务/视频生成
  - name: AI 服务/图像生成
  - name: 渠道管理
  - name: 渠道管理/账号
  - name: 渠道管理/内容发布
  - name: 渠道管理/平台
  - name: 渠道管理/作品
  - name: 渠道管理/账号分组
  - name: 渠道管理/授权
  - name: 资源管理
  - name: AI 服务/大语言模型
  - name: AI 服务/真人素材
  - name: AI 服务/Agent
paths:
  /api/ai/images/generations:
    post:
      tags:
        - AI 服务/图像生成
      summary: OpenAI 图像生成
      description: >-
        接口说明：OpenAI Images API `/v1/images/generations`
        的兼容端点（文生图）。请求、响应与错误格式完全遵循 OpenAI 规范：返回 OpenAI 原始 `ImagesResponse`，不使用
        AiToEarn 通用响应包裹；图片链接为上游原始返回，不做转存。鉴权使用 `Authorization: Bearer <API
        Key>`（OpenAI SDK 默认携带），已有 OpenAI SDK 或生态工具只需替换 baseURL 与 API Key 即可接入，按
        AiToEarn 积分计费。


        模型取值来自[「图像生成模型」](/api-reference/get-api-ai-models-image-generation)接口返回的
        `data[n].name`。如需 AiToEarn 通用响应格式（`code ===
        0`）与转存后的稳定图片链接，请改用[「生成图像」](/api-reference/post-api-ai-image-generate)接口。
      operationId: RelayController_imagesGenerations
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                prompt:
                  type: string
                  example: A cute orange cat sitting by a window, soft natural light
                model:
                  type: string
                  description: >-
                    图像生成模型名称。先调用[「图像生成模型」](/api-reference/get-api-ai-models-image-generation)接口（`GET
                    /api/ai/models/image/generation`），传入其返回的
                    `data[n].name`；各模型支持的尺寸、质量、风格与价格以该接口返回为准。
                  example: gpt-image-2
                quality:
                  description: >-
                    图像质量。可选值随模型而不同，以[「图像生成模型」](/api-reference/get-api-ai-models-image-generation)接口返回的
                    `data[n].qualities` 为准。
                  type: string
                  example: low
                response_format:
                  type: string
                  enum:
                    - url
                    - b64_json
                  example: url
                size:
                  description: >-
                    图像尺寸。可选值随模型而不同，以[「图像生成模型」](/api-reference/get-api-ai-models-image-generation)接口返回的
                    `data[n].sizes` 为准；不同尺寸的价格不同，见 `data[n].pricing`。
                  type: string
                  example: 1024x1024
              required:
                - prompt
                - model
              additionalProperties: true
              example:
                prompt: A cute orange cat sitting by a window, soft natural light
                model: gpt-image-2
                quality: low
                response_format: url
                size: 1024x1024
            examples:
              lowest-cost:
                summary: 最低积分示例
                value:
                  prompt: A cute orange cat sitting by a window, soft natural light
                  model: gpt-image-2
                  quality: low
                  response_format: url
                  size: 1024x1024
        required: true
      responses:
        '200':
          description: 第三方协议原生响应或 SSE 数据。不使用 AiToEarn 通用响应包裹。
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        url:
                          type: string
                  created:
                    type: number
                  quality:
                    type: string
                  size:
                    type: string
                  usage:
                    type: object
                    properties:
                      input_tokens:
                        type: number
                      output_tokens:
                        type: number
                      total_tokens:
                        type: number
                      input_tokens_details:
                        type: object
                        properties:
                          text_tokens:
                            type: number
                          image_tokens:
                            type: number
                      output_tokens_details:
                        type: object
                        properties:
                          text_tokens:
                            type: number
                          image_tokens:
                            type: number
                additionalProperties: true
                example:
                  data:
                    - url: string
                  created: number
                  quality: string
                  size: string
                  usage:
                    input_tokens: number
                    output_tokens: number
                    total_tokens: number
                    input_tokens_details:
                      text_tokens: number
                      image_tokens: number
                    output_tokens_details:
                      text_tokens: number
                      image_tokens: number
              examples:
                success:
                  summary: 第三方协议原生成功响应
                  value:
                    data:
                      - url: string
                    created: number
                    quality: string
                    size: string
                    usage:
                      input_tokens: number
                      output_tokens: number
                      total_tokens: number
                      input_tokens_details:
                        text_tokens: number
                        image_tokens: number
                      output_tokens_details:
                        text_tokens: number
                        image_tokens: number
            text/event-stream:
              schema:
                type: string
      deprecated: false
      security:
        - apikey-header-Authorization: []
components:
  securitySchemes:
    apikey-header-Authorization:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        传入从 AiToEarn 获取 API Key。点击前往[「API Key 获取教程」](/zh/use/api-key)。示例：Bearer
        xxx。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.