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

# Gemini 2.5 Flash Image 示例

> 使用稳定模型 ID 完成同步生成、异步提交和 Base64 图片读取。

## 同步生成

```bash theme={"system"}
curl 'https://api.yingtu.ai/v1beta/models/gemini-2.5-flash-image:generateContent' \
  -H 'Authorization: Bearer YOUR_YINGTU_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "contents": [{"role": "user", "parts": [{"text": "白色书架上的釉面陶瓷小鸟"}]}],
    "generationConfig": {
      "responseModalities": ["TEXT", "IMAGE"],
      "imageConfig": {"aspectRatio": "1:1"}
    }
  }'
```

代表性成功响应中，图片不在第一个 part：

```json theme={"system"}
{
  "candidates": [{
    "content": {
      "role": "model",
      "parts": [
        {"text": "图片已生成。"},
        {"inlineData": {"mimeType": "image/png", "data": "BASE64_IMAGE_DATA"}}
      ]
    },
    "finishReason": "STOP",
    "index": 0
  }],
  "modelVersion": "gemini-2.5-flash-image",
  "responseId": "response_example"
}
```

## 改为异步

请求体不变，只把方法后缀改成 `:asyncGenerateContent`。保存 HTTP `202` 返回的
`task_id`，再查询 `/v1/tasks/{task_id}`。实测任务经过 `in_progress` 后返回
`completed` 和 1024 × 1024 PNG。

```python theme={"system"}
import base64

for candidate in result["candidates"]:
    for part in candidate["content"]["parts"]:
        if "inlineData" in part:
            image_bytes = base64.b64decode(part["inlineData"]["data"])
            mime_type = part["inlineData"]["mimeType"]
```

## 在线测试

本页已经嵌入固定路径 `gemini-2.5-flash-image:generateContent` 的真实 OpenAPI
**试一试** 表单。填入开发凭证、确认请求体后即可同步生成，不需要跳转到 API 参考。

<Warning>在线测试会产生真实费用。Mintlify 会在生成的 cURL 中显示已输入的 Key，请勿分享带凭证的截图。</Warning>


## OpenAPI

````yaml openapi-models/gemini-2.5-flash-image.json POST /v1beta/models/gemini-2.5-flash-image:generateContent
openapi: 3.1.0
info:
  title: YingTu gemini-2.5-flash-image API
  version: 1.0.0
  description: >-
    Model-fixed synchronous image generation and editing for
    gemini-2.5-flash-image.
servers:
  - url: https://api.yingtu.ai
    description: YingTu API
security: []
tags:
  - name: Synchronous generation
    description: Wait for a complete Gemini response in one HTTP request.
  - name: Asynchronous tasks
    description: >-
      Submit image work, then retrieve the task until it reaches a terminal
      state.
paths:
  /v1beta/models/gemini-2.5-flash-image:generateContent:
    post:
      tags:
        - Synchronous generation
      summary: Generate an image with gemini-2.5-flash-image
      description: >-
        Generate or edit an image with the fixed YingTu model ID
        gemini-2.5-flash-image.
      operationId: generateImageSynchronously_gemini_2.5_flash_image
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PlaygroundGenerateImageRequest'
            examples:
              textToImage:
                summary: Generate a 2K landscape image
                value:
                  contents:
                    - role: user
                      parts:
                        - text: >-
                            A single yellow ceramic banana on a matte white
                            background, soft studio lighting, no text.
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '1:1'
      responses:
        '200':
          description: Complete Gemini response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateContentResponse'
              examples:
                verifiedImageResult:
                  summary: Representative completed image response
                  value:
                    candidates:
                      - content:
                          role: model
                          parts:
                            - inlineData:
                                mimeType: image/png
                                data: BASE64_IMAGE_DATA
                        finishReason: STOP
                        index: 0
                    usageMetadata:
                      promptTokenCount: 37
                      candidatesTokenCount: 1846
                      totalTokenCount: 1883
                      promptTokensDetails:
                        - modality: TEXT
                          tokenCount: 37
                      candidatesTokensDetails:
                        - modality: IMAGE
                          tokenCount: 1680
                    modelVersion: gemini-2.5-flash-image
                    responseId: response_example
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/ServerError'
      security:
        - BearerAuth: []
components:
  schemas:
    PlaygroundGenerateImageRequest:
      title: Image request
      type: object
      required:
        - contents
      properties:
        contents:
          title: Prompt and input
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/PlaygroundRequestContent'
          description: Prompt and optional source image.
        generationConfig:
          $ref: '#/components/schemas/PlaygroundGenerationConfig'
          title: Output settings
    GenerateContentResponse:
      type: object
      required:
        - candidates
      properties:
        candidates:
          type: array
          items:
            $ref: '#/components/schemas/Candidate'
        usageMetadata:
          $ref: '#/components/schemas/UsageMetadata'
        modelVersion:
          type: string
          description: The model version that produced the response.
          example: gemini-2.5-flash-image
        responseId:
          type: string
          description: Provider response identifier.
          example: response_example
        createTime:
          type: string
          format: date-time
          description: Creation time when supplied by the selected model channel.
    PlaygroundRequestContent:
      title: Message
      type: object
      required:
        - parts
      properties:
        parts:
          title: Prompt or source image
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/PlaygroundRequestPart'
          description: Start with text; add an image to edit.
        role:
          title: Role
          type: string
          enum:
            - user
          example: user
          x-default: user
          description: Request sender.
    PlaygroundGenerationConfig:
      title: Output settings
      type: object
      properties:
        responseModalities:
          title: Response type
          type: array
          minItems: 1
          uniqueItems: true
          items:
            type: string
            enum:
              - TEXT
              - IMAGE
          example:
            - TEXT
            - IMAGE
          x-default:
            - TEXT
            - IMAGE
          description: Include IMAGE.
        imageConfig:
          $ref: '#/components/schemas/PlaygroundImageConfig'
          title: Image settings
        candidateCount:
          title: Number of outputs
          type: integer
          enum:
            - 1
          description: Use one output.
    Candidate:
      type: object
      required:
        - content
      properties:
        content:
          $ref: '#/components/schemas/ResponseContent'
        finishReason:
          type: string
          example: STOP
        index:
          type: integer
          minimum: 0
          example: 0
    UsageMetadata:
      type: object
      properties:
        promptTokenCount:
          type: integer
          minimum: 0
        candidatesTokenCount:
          type: integer
          minimum: 0
        totalTokenCount:
          type: integer
          minimum: 0
        thoughtsTokenCount:
          type: integer
          minimum: 0
        promptTokensDetails:
          type: array
          items:
            $ref: '#/components/schemas/ModalityTokenCount'
        candidatesTokensDetails:
          type: array
          items:
            $ref: '#/components/schemas/ModalityTokenCount'
        serviceTier:
          type: string
        trafficType:
          type: string
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/ErrorObject'
    PlaygroundRequestPart:
      title: Input part
      description: Choose text or a source image.
      oneOf:
        - $ref: '#/components/schemas/PlaygroundTextPart'
        - $ref: '#/components/schemas/PlaygroundInlineImagePart'
    PlaygroundImageConfig:
      title: Image settings
      type: object
      properties:
        aspectRatio:
          title: Aspect ratio
          type: string
          enum:
            - '1:1'
            - '2:3'
            - '3:2'
            - '3:4'
            - '4:3'
            - '4:5'
            - '5:4'
            - '9:16'
            - '16:9'
            - '21:9'
          example: '1:1'
          x-default: '1:1'
          description: Output shape.
    ResponseContent:
      type: object
      required:
        - parts
      properties:
        role:
          type: string
          const: model
        parts:
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/ResponsePart'
    ModalityTokenCount:
      type: object
      required:
        - modality
        - tokenCount
      properties:
        modality:
          type: string
          example: IMAGE
        tokenCount:
          type: integer
          minimum: 0
    ErrorObject:
      type: object
      required:
        - message
        - type
      properties:
        message:
          type: string
        type:
          type: string
          example: invalid_request_error
        code:
          type:
            - string
            - 'null'
    PlaygroundTextPart:
      title: Text prompt
      type: object
      required:
        - text
      properties:
        text:
          title: Prompt
          type: string
          example: >-
            A single yellow ceramic banana on a matte white background, soft
            studio lighting, no text.
          x-default: >-
            A single yellow ceramic banana on a matte white background, soft
            studio lighting, no text.
          description: Prompt or edit instruction.
    PlaygroundInlineImagePart:
      title: Source image
      type: object
      required:
        - inlineData
      properties:
        inlineData:
          $ref: '#/components/schemas/PlaygroundInlineImage'
          title: Source image
    ResponsePart:
      type: object
      properties:
        text:
          type: string
        inlineData:
          $ref: '#/components/schemas/InlineData'
        fileData:
          $ref: '#/components/schemas/FileData'
        functionCall:
          $ref: '#/components/schemas/FunctionCall'
        functionResponse:
          $ref: '#/components/schemas/FunctionResponse'
        executableCode:
          $ref: '#/components/schemas/ExecutableCode'
        codeExecutionResult:
          $ref: '#/components/schemas/CodeExecutionResult'
        thought:
          type: boolean
        thoughtSignature:
          type: string
          format: byte
        partMetadata:
          type: object
          additionalProperties: true
        mediaResolution:
          type: object
          additionalProperties: true
        videoMetadata:
          type: object
          additionalProperties: true
      description: >-
        A Gemini response Part. Part data fields are mutually exclusive in the
        Gemini protocol.
    PlaygroundInlineImage:
      title: Inline image
      type: object
      required:
        - mimeType
        - data
      properties:
        mimeType:
          title: Image MIME type
          type: string
          enum:
            - image/png
            - image/jpeg
            - image/webp
          example: image/png
          description: Match the source bytes.
        data:
          title: Image Base64
          type: string
          example: BASE64_SOURCE_IMAGE
          description: Raw Base64; omit the data URL prefix.
    InlineData:
      title: Inline image
      type: object
      required:
        - mimeType
        - data
      properties:
        mimeType:
          title: Image MIME type
          type: string
          enum:
            - image/png
            - image/jpeg
            - image/webp
          example: image/png
        data:
          title: Image Base64
          type: string
          description: Raw Base64 without a data URL prefix.
          example: BASE64_IMAGE_DATA
    FileData:
      type: object
      required:
        - fileUri
      properties:
        mimeType:
          type: string
          description: Optional IANA MIME type.
        fileUri:
          type: string
          description: URI of a Gemini File API resource.
    FunctionCall:
      type: object
      required:
        - name
        - args
      properties:
        id:
          type: string
        name:
          type: string
        args:
          type: object
          additionalProperties: true
    FunctionResponse:
      type: object
      required:
        - name
        - response
      properties:
        id:
          type: string
        name:
          type: string
        response:
          type: object
          additionalProperties: true
    ExecutableCode:
      type: object
      required:
        - language
        - code
      properties:
        language:
          type: string
        code:
          type: string
    CodeExecutionResult:
      type: object
      required:
        - outcome
        - output
      properties:
        outcome:
          type: string
        output:
          type: string
  responses:
    BadRequest:
      description: Invalid model, field, or parameter value
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Missing or invalid YingTu API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    RateLimited:
      description: Rate limit exceeded
      headers:
        Retry-After:
          description: Seconds to wait before retrying when supplied.
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    ServerError:
      description: The request could not be completed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key
      description: YingTu API key.

````