> ## 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.

# Generate Image

> Interface description: Generate images synchronously, and return the generation results based on the selected model and prompt words.

Before calling this interface, please request the ["Image Generation Model"](/en/api-reference/get-api-ai-models-image-generation) interface (`GET /api/ai/models/image/generation`) to obtain the currently available model list and the size, quality, style and price supported by each model, and then fill in the parameters of this interface accordingly.

The image is generated as **Wen Sheng Picture**: Generate a new image only through text prompts, without passing in pictures. If you need to modify or redraw based on existing images, please use the ["Edit Image"](/en/api-reference/post-api-ai-image-edit) interface.

If you are already using the OpenAI SDK or ecological tools, you can use the OpenAI compatible endpoint ["OpenAI Image Generation"](/en/api-reference/post-api-ai-images-generations) instead.



## OpenAPI

````yaml /openapi/en/aitoearn.openapi.json post /api/ai/image/generate
openapi: 3.0.1
info:
  title: AiToEarn Open Platform API
  description: >-
    AiToEarn Open Platform API. You can switch between the China and
    international sites for testing. Business success is determined by whether
    the response body has code === 0.
  version: 1.0.0
  contact: {}
servers:
  - url: https://aitoearn.cn
    description: China site
  - url: https://aitoearn.ai
    description: International site
security: []
tags:
  - name: AI Services
  - name: AI Services/Video Generation
  - name: AI Services/Image Generation
  - name: Channel Management
  - name: Channel Management/Accounts
  - name: Channel Management/Publishing
  - name: Channel Management/Platforms
  - name: Channel Management/Works
  - name: Channel Management/Account Groups
  - name: Channel Management/Authorization
  - name: Asset Management
  - name: AI Services/Large Language Models
paths:
  /api/ai/image/generate:
    post:
      tags:
        - AI Services/Image Generation
      summary: Generate Image
      description: >-
        Interface description: Generate images synchronously, and return the
        generation results based on the selected model and prompt words.


        Before calling this interface, please request the ["Image Generation
        Model"](/en/api-reference/get-api-ai-models-image-generation) interface
        (`GET /api/ai/models/image/generation`) to obtain the currently
        available model list and the size, quality, style and price supported by
        each model, and then fill in the parameters of this interface
        accordingly.


        The image is generated as **Wen Sheng Picture**: Generate a new image
        only through text prompts, without passing in pictures. If you need to
        modify or redraw based on existing images, please use the ["Edit
        Image"](/en/api-reference/post-api-ai-image-edit) interface.


        If you are already using the OpenAI SDK or ecological tools, you can use
        the OpenAI compatible endpoint ["OpenAI Image
        Generation"](/en/api-reference/post-api-ai-images-generations) instead.
      operationId: ImageController_generateImage
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                prompt:
                  type: string
                  minLength: 1
                  maxLength: 4000
                  description: Image description tips
                model:
                  type: string
                  description: >-
                    Image generation model name. First call the ["Image
                    Generation
                    Model"](/en/api-reference/get-api-ai-models-image-generation)
                    interface (`GET /api/ai/models/image/generation`) and pass
                    in the `data[n].name` returned by it; the size, quality,
                    style and price supported by each model shall be subject to
                    the return of this interface.
                'n':
                  description: Number of images generated
                  type: integer
                  minimum: 1
                  maximum: 10
                quality:
                  type: string
                  description: >-
                    Image quality. The optional values ​​vary from model to
                    model, and are subject to the `data[n].qualities` returned
                    by the ["Image Generation
                    Model"](/en/api-reference/get-api-ai-models-image-generation)
                    interface.
                response_format:
                  type: string
                  enum:
                    - url
                    - b64_json
                  description: Return format
                size:
                  type: string
                  description: >-
                    Image size. The optional values ​​vary with the model, and
                    are subject to the `data[n].sizes` returned by the ["Image
                    Generation
                    Model"](/en/api-reference/get-api-ai-models-image-generation)
                    interface; the prices for different sizes are different, see
                    `data[n].pricing`.
                style:
                  type: string
                  description: >-
                    Image style. The optional values ​​vary with the model, and
                    are subject to the `data[n].styles` returned by the ["Image
                    Generation
                    Model"](/en/api-reference/get-api-ai-models-image-generation)
                    interface; returning empty means that the model does not
                    support style parameters.
              required:
                - prompt
                - model
            examples: {}
        required: true
      responses:
        '200':
          description: >-
            The request has been processed by the service. Business success is
            determined by whether the response body has code === 0.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/ImageResponseVo'
                  code:
                    type: integer
                    description: >-
                      Business status code. 0 means success; non-zero means a
                      business error.
                  message:
                    type: string
                    description: Response message.
                  requestId:
                    type: string
                    description: Request ID.
                  timestamp:
                    type: integer
                    description: Error response timestamp in Unix milliseconds.
                required:
                  - code
                  - message
              examples:
                success:
                  summary: Success
                  value:
                    code: 0
                    message: Request succeeded
                    data:
                      created: 1
                      list:
                        - url: string
                          b64_json: string
                          revised_prompt: string
                      usage:
                        input_tokens: 1
                        output_tokens: 1
                        total_tokens: 1
                      background: string
                      output_format: string
                      quality: string
                      size: string
                validationFailed10002:
                  summary: ValidationFailed (10002)
                  value:
                    code: 10002
                    message: Parameter validation failed
                    data: {}
                    timestamp: 1772099056662
                unauthorized401:
                  summary: Unauthenticated or invalid API Key
                  value:
                    code: 401
                    message: Unauthorized
                    data: {}
                    timestamp: 1772099056662
                invalidModel12300:
                  summary: InvalidModel (12300)
                  value:
                    code: 12300
                    message: Invalid AI model
                    data: {}
                    timestamp: 1772099056662
      deprecated: false
      security:
        - apikey-header-X-Api-Key: []
components:
  schemas:
    ImageResponseVo:
      type: object
      properties:
        created:
          type: number
          description: Create timestamp
        list:
          type: array
          items:
            type: object
            properties:
              url:
                description: Image URL
                type: string
              b64_json:
                description: base64 encoded image
                type: string
              revised_prompt:
                description: Revised prompt words
                type: string
            additionalProperties: false
          description: Generated image list
        usage:
          description: token usage
          type: object
          properties:
            input_tokens:
              description: Enter the number of tokens
              type: number
            output_tokens:
              description: Output the number of tokens
              type: number
            total_tokens:
              description: Total number of tokens
              type: number
          additionalProperties: false
        background:
          type: string
          description: background
        output_format:
          type: string
          description: Output format
        quality:
          type: string
          description: Quality level
        size:
          type: string
          description: Image size
      required:
        - created
        - list
      additionalProperties: false
  securitySchemes:
    apikey-header-X-Api-Key:
      type: apiKey
      in: header
      name: X-Api-Key
      description: >-
        Need to get API Key from AiToEarn. Click to go to ["API Key Obtaining
        Tutorial"](/en/use/api-key).

````