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

# GPT-生成图像 [非官转]

> 根据文本提示以及图片资源生成图片



## OpenAPI

````yaml openapi/cn/openai.json POST /openai/gpt/generations
openapi: 3.1.0
info:
  title: Open AI API DOCS
  version: 1.0.0
  description: TTAPI Open AI API 接口服务
servers:
  - url: https://api.ttapi.io
security: []
paths:
  /openai/gpt/generations:
    post:
      description: 根据文本提示以及图片资源生成图片
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GptgenerationsRequest'
      responses:
        '200':
          $ref: '#/components/responses/SuccessResponse'
        '400':
          $ref: '#/components/responses/400Response'
        '401':
          $ref: '#/components/responses/401Response'
      security:
        - CustomApiKey: []
components:
  schemas:
    GptgenerationsRequest:
      type: object
      properties:
        model:
          type: string
          description: 支持模型
          enum:
            - gpt-image-1.5
            - gpt-image-2
            - gpt-image-2-plus
          default: gpt-image-2
        prompt:
          type: string
          description: >-
            生成图片文字提示，因为目前为逆向模型，建议文案提示存在关键字：** “画一张xxx”, “生成一张”，'draw a xxx'， **
            具体语言不限制，openai本身就支持多语言模型，中文支持也非常友好。
        referImages:
          type: array
          description: 垫图数组
          items:
            type: string
          example:
            - https://cdn.ttapi.io/xxx1.png
            - https://cdn.ttapi.io/xxx2.png
        aspect_ratio:
          type: string
          description: 图像宽高比，参数支持模型：`gpt-image-2`
          enum:
            - '1:1'
            - '3:4'
            - '4:3'
            - '16:9'
            - '9:16'
          example: '1:1'
        size:
          type: string
          description: |-
            图像尺寸（width × height），参数支持模型：`gpt-image-2-plus` 

            需满足以下限制：

            宽高必须为 16 的倍数
            最长边 ≤ 3840
            宽高比 ≤ 3:1
            总像素：655,360 ~ 8,294,400

             不符合规则时，系统会自动修正到合法范围
          example: 1024x1024
        hookUrl:
          type: string
          description: >-
            回调通知地址，任务完成或失败将通过请地址进行通知，<a href="gpt-fetch"
            target="_self">通知数据结构</a>与fetch结构一致。如果未设置，则需要请求<a href="gpt-fetch"
            target="_self">fetch接口</a>进行查询
      required:
        - prompt
  responses:
    SuccessResponse:
      description: 请求成功
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: SUCCESS
              message:
                type: string
                example: success
              data:
                type: object
                example:
                  jobId: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            required:
              - status
              - message
              - data
    400Response:
      description: 参数错误
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: FAILED
              message:
                type: string
                example: '"prompt" cannot be empty.'
              data:
                type: object
            required:
              - status
              - message
    401Response:
      description: 授权失败
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: FAILED
              message:
                type: string
                example: Wrong TT-API-KEY or email is not activated.
            required:
              - status
              - message
  securitySchemes:
    CustomApiKey:
      type: apiKey
      in: header
      name: TT-API-KEY
      description: >-
        请前往 <a href='https://dashboard.ttapi.io' target='_blank'>TTAPI 控制台</a>
        获取 API 密钥。

````