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

# 图像理解

> 使用返回的任务 ID [进行查询](/pages/zh/api-manual/task-management/get-task-detail) 获取最终结果。



## OpenAPI

````yaml openapi/zh/llm-vision.json POST /v1/llm/generations
openapi: 3.1.0
info:
  title: LLM · llm-vision protocol
  version: '1.0'
  description: >-
    统一 LLM 入口的 **`llm-vision`** 请求格式：`prompt` + `image_urls[]`（1–10 张）→ 视觉理解。


    **`/v1/llm/generations` 端点支持 5 种请求形态**：

    - `llm-text`：仅 `prompt`

    - `llm-vision`（本文件）：`prompt` + `image_urls[]`

    - `llm-video`：`prompt` + `video_urls[]`

    - `llm-audio`：`audio_url`

    - `llm-custom`：`messages[]`（OpenAI Chat 兼容）


    **image_urls 接受 URL 或 base64 data URI**：

    - HTTP/HTTPS URL（公网可达）

    - `data:image/<png|jpeg|webp|gif>;base64,<payload>` data URI（base64 内联）


    任务最终结果通过 `GET /v1/tasks/{task_id}` 查询；SSE 流式订阅端点为 `GET
    /v1/llm/generations/{task_id}/stream`，所有 5 种 protocol 共用。
servers:
  - url: https://api.aihubmax.com
security:
  - BearerAuth: []
paths:
  /v1/llm/generations:
    post:
      tags:
        - LLM > llm-vision
      summary: 提交 LLM 生成任务（llm-vision 协议）
      description: >-
        使用返回的任务 ID [进行查询](/pages/zh/api-manual/task-management/get-task-detail)
        获取最终结果。
      operationId: llm-vision
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LLMVisionRequest'
            examples:
              example_0:
                summary: Async — describe an image
                value:
                  model: claude-opus-4-7
                  prompt: Describe this image in one sentence.
                  image_urls:
                    - https://fal.media/files/lion/AOtzfcyHpx-MOITAUeMrK.jpeg
                  max_tokens: 64
              example_1:
                summary: Sync streaming — multi-image
                value:
                  model: gemini-2.5-pro
                  prompt: What is common to all of these images?
                  image_urls:
                    - https://fal.media/files/lion/AOtzfcyHpx-MOITAUeMrK.jpeg
                    - https://fal.media/files/penguin/QxEROl7HcfUomtBEkSYXG.jpg
                  sync: true
                  stream: true
              example_2:
                summary: >-
                  Inline base64 image (data URI) — works on flaky upstream
                  egress
                value:
                  model: gemini-2.5-pro
                  prompt: Describe in one word.
                  image_urls:
                    - >-
                      data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNgAAIAAAUAAen63NgAAAAASUVORK5CYII=
                  max_tokens: 8
      responses:
        '200':
          description: 任务已创建（async 模式）/ 完整响应（sync 模式）
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubmitResponse'
              examples:
                non_stream:
                  summary: sync=false, stream=false
                  value:
                    id: task-llmrouter-1776874481-rj6bs3yb
                    object: llm.generation.task
                    type: llm
                    model: claude-opus-4-7
                    status: pending
                    progress: 0
                    created: 1776874481
                    stream: null
                    results: null
                    error: null
                stream:
                  summary: sync=false, stream=true
                  value:
                    id: task-llmrouter-1776874565-yq3szvcu
                    object: llm.generation.task
                    type: llm
                    model: gemini-2.5-pro
                    status: pending
                    progress: 0
                    created: 1776874565
                    stream:
                      url: >-
                        /v1/llm/generations/task-llmrouter-1776874565-yq3szvcu/stream
                    results: null
                    error: null
        '401':
          $ref: '#/components/responses/Unauthorized'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
components:
  schemas:
    LLMVisionRequest:
      type: object
      required:
        - model
        - prompt
        - image_urls
      additionalProperties: true
      properties:
        model:
          type: string
          description: >-
            [获取模型列表](/pages/zh/api-manual/text-series/llm-async/llm-generations-models)
          example: claude-opus-4-7
        prompt:
          type: string
          maxLength: 100000
          description: 用户提示词，最多 100,000 字符。
          example: Describe this image in one sentence.
        image_urls:
          type: array
          minItems: 1
          maxItems: 10
          description: >-
            图片源数组（1–10 张）。每个元素接受以下两种形式：

            - 公网 HTTP/HTTPS URL

            - `data:image/<type>;base64,<payload>` data URI（base64 内联）


            **模型限制**：上限张数由所选模型对应上游决定；当某模型仅支持单图而请求传入多张时，路由层返回 422
            `model_rule_violation`（具体规则维护在
            `app/relays/llm_router/model_rules.py`，覆盖渠道配置以外的「模型固有」约束）。


            **内联 base64（仅异步模式，`sync` 省略或为 `false`）**：网关识别为内联媒体的 base64（`data:`
            URI，或 4096 个以上编码字符且解码内容命中已知媒体签名的裸 base64），会在请求入库与提交上游之前上传文件存储并替换为
            URL，不以 base64 原文入库；更短的裸 base64、或签名不可识别的内容按原样透传，也不做体积校验。上限只作用于内联
            base64 项（公网 http(s) URL 不受限）：单项解码后 ≤ 5 MB、单数组内联 ≤ 5 项、单请求合计 ≤ 10
            MB、单请求内联总数 ≤ 20 项。`data:` 前缀格式非法或 payload 解码为 0 字节返回 422，超限同样返回
            422，请改用 `/v1/files/upload` 上传后传 URL。


            `sync: true` 时请求不写任务记录，以上均不适用：内联 base64 原样提交上游，不做任何体积或数量校验。
          items:
            type: string
          example:
            - https://fal.media/files/lion/AOtzfcyHpx-MOITAUeMrK.jpeg
        sync:
          type: boolean
          default: false
          description: 同步模式（参见 llm-text schema）。
          example: false
        stream:
          type: boolean
          default: false
          description: 是否流式（参见 llm-text schema）。
          example: false
        max_tokens:
          type: integer
          nullable: true
          minimum: 1
          description: 生成 token 上限。可选。
          example: 64
        temperature:
          type: number
          nullable: true
          minimum: 0
          maximum: 2
          description: 采样温度，区间 [0, 2]。可选。
          example: 0.3
        system_prompt:
          type: string
          nullable: true
          maxLength: 10000
          description: 系统指令。可选。
          example: You are a vision assistant.
        reasoning:
          type: boolean
          nullable: true
          description: 是否包含 reasoning tokens。部分思考模型需设为 `true`。
    SubmitResponse:
      type: object
      description: >-
        Submit 响应，对齐统一任务标准形状。`results` / `error` 在 submit 阶段固定为
        `null`，任务完成/失败后通过 `GET /v1/tasks/{task_id}` 返回。`sync=true, stream=false`
        模式下端点直接返回完整 OpenAI ChatCompletion JSON。
      required:
        - id
        - object
        - type
        - model
        - status
        - progress
        - created
      properties:
        id:
          type: string
          description: 任务 ID，格式 `task-llmrouter-{timestamp}-{8random}`。
          example: task-llmrouter-1776874565-yq3szvcu
        object:
          type: string
          enum:
            - llm.generation.task
          example: llm.generation.task
        type:
          type: string
          enum:
            - llm
          example: llm
        model:
          type: string
          description: 客户端提交的模型名（原样回显）
          example: claude-opus-4-7
        status:
          type: string
          enum:
            - pending
          example: pending
        progress:
          type: integer
          example: 0
        created:
          type: integer
          example: 1776874565
        stream:
          nullable: true
          description: '`stream=true` 时返回 `{url: ...}`；`stream=false` 时为 `null`。'
          oneOf:
            - $ref: '#/components/schemas/StreamInfo'
            - type: 'null'
        results:
          type: array
          nullable: true
          description: >-
            submit 阶段固定 `null`；任务完成后通过 `GET /v1/tasks/{task_id}` 返回，`results[0]`
            为完整 OpenAI `ChatCompletion` 响应。
          items:
            type: object
          example: null
        error:
          type: object
          nullable: true
          description: submit 阶段固定 `null`；任务失败时通过 `GET /v1/tasks/{task_id}` 返回。
          example: null
    StreamInfo:
      type: object
      required:
        - url
      properties:
        url:
          type: string
          example: /v1/llm/generations/task-llmrouter-1776874565-yq3szvcu/stream
    ErrorResponse401:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 未提供认证 token
            type:
              type: string
              example: authentication_error
    ErrorResponse422:
      type: object
      description: >-
        参数校验失败。常见
        `code`：`model_rule_violation`（命中模型固有规则，如单图模型收到多张）、`model_not_support_capability`（候选渠道未声明
        `vision`
        能力）、`model_not_registered`、`invalid_param`、`upstream_client_error`。
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: >-
                model 'xxx' only accepts a single image_url; received
                image_urls.length=3
            type:
              type: string
              example: invalid_request_error
            code:
              type: string
              example: model_input_not_supported
    ErrorResponse429:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 请求频率超限
            type:
              type: string
              example: rate_limit_error
    ErrorResponse500:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: Internal server error
            type:
              type: string
              example: internal_error
    ErrorResponse503:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 'all 3 candidates exhausted; last error: ...'
            type:
              type: string
              example: upstream_error
            code:
              type: string
              example: all_platforms_exhausted
  responses:
    Unauthorized:
      description: Token 无效或缺失
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse401'
    UnprocessableEntity:
      description: 参数校验失败 / 模型固有约束（如单图模型收到多张）/ 候选渠道未声明 `vision` 能力 / 模型未注册 / 上游 4xx
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse422'
    TooManyRequests:
      description: 请求频率超限
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse429'
    InternalServerError:
      description: 服务器内部错误
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse500'
    ServiceUnavailable:
      description: 上游服务不可用
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse503'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |-
        所有接口均需要使用 Bearer Token 进行认证。在请求头中添加：

        `Authorization: Bearer YOUR_API_KEY`

        `YOUR_API_KEY` 为 API Token（`sk-...` 格式）。

````