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

# Claude 格式 - 消息

> - 适用于所有兼容 Claude 格式模型的通用 Anthropic Messages API 参考
- 最简化参数，快速上手
- 发送包含文本内容的结构化输入消息列表
- 系统提示词：自定义 AI 的角色和行为
- 支持流式和非流式响应




## OpenAPI

````yaml openapi/zh/claude-format-messages.json POST /v1/messages
openapi: 3.1.0
info:
  title: Claude Format - Messages
  version: '1.0'
servers:
  - url: https://api.aihubmax.com
security:
  - BearerAuth: []
paths:
  /v1/messages:
    post:
      tags:
        - Text Series > Claude Format
      summary: Claude Format - Messages
      description: |
        - 适用于所有兼容 Claude 格式模型的通用 Anthropic Messages API 参考
        - 最简化参数，快速上手
        - 发送包含文本内容的结构化输入消息列表
        - 系统提示词：自定义 AI 的角色和行为
        - 支持流式和非流式响应
      operationId: claude-format-messages
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClaudeMessagesRequest'
            examples:
              single-turn:
                summary: 单轮对话
                description: 最基础的单轮问答
                value:
                  model: claude-sonnet-4-6
                  max_tokens: 1024
                  messages:
                    - role: user
                      content: 比较 PostgreSQL 和 MySQL 的主要区别
              multi-turn:
                summary: 多轮对话
                description: 包含系统提示词和多轮上下文
                value:
                  model: claude-sonnet-4-6
                  max_tokens: 2048
                  system: 你是一位经验丰富的产品经理，擅长用户需求分析和产品设计
                  messages:
                    - role: user
                      content: 我们的 SaaS 产品用户留存率只有 30%，怎么改善？
                    - role: assistant
                      content: |-
                        30% 的留存率确实偏低。我需要了解更多信息来给出针对性建议：
                        1. 这是 7 日留存还是 30 日留存？
                        2. 用户主要在哪个环节流失？
                        3. 你们有做用户访谈或问卷调查吗？
                    - role: user
                      content: 是30日留存，用户主要在注册后第3天流失，还没做过用户调研
              streaming:
                summary: 流式响应
                description: 启用流式输出，实时获取生成内容
                value:
                  model: claude-sonnet-4-6
                  max_tokens: 4096
                  messages:
                    - role: user
                      content: 写一篇关于微服务架构优缺点的技术博客
                  stream: true
              with-image:
                summary: 带图片
                description: 发送图片让模型分析（视觉理解）
                value:
                  model: claude-sonnet-4-6
                  max_tokens: 1024
                  messages:
                    - role: user
                      content:
                        - type: text
                          text: 这个 UI 设计有哪些可以改进的地方？
                        - type: image
                          source:
                            type: url
                            url: >-
                              https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg
              with-pdf:
                summary: 带文件（PDF）
                description: 发送 PDF 文件让模型分析文档内容
                value:
                  model: claude-sonnet-4-6
                  max_tokens: 4096
                  messages:
                    - role: user
                      content:
                        - type: text
                          text: 请总结这份文档的核心内容，提取关键要点
                        - type: document
                          source:
                            type: url
                            url: https://example.com/report.pdf
      responses:
        '200':
          $ref: '#/components/responses/ClaudeMessagesSuccess'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    ClaudeMessagesRequest:
      type: object
      required:
        - model
        - messages
        - max_tokens
      properties:
        model:
          type: string
          description: 模型名称，如 claude-sonnet-4-6
          example: claude-sonnet-4-6
        messages:
          type: array
          description: 对话消息列表
          items:
            type: object
            required:
              - role
              - content
            properties:
              role:
                type: string
                description: 消息发送者的角色
                enum:
                  - user
                  - assistant
              content:
                type: string
                description: 消息内容
        max_tokens:
          type: integer
          description: 最大生成token数（必填）
        system:
          oneOf:
            - type: string
              description: 系统提示词（文本形式）
            - type: array
              description: 系统提示词（结构化形式）
              items:
                type: object
                properties:
                  type:
                    type: string
                    enum:
                      - text
                  text:
                    type: string
          description: 系统提示词
        temperature:
          type: number
          description: 采样温度 (0-1)
          minimum: 0
          maximum: 1
        top_p:
          type: number
          description: 核采样参数 (0-1)
          minimum: 0
          maximum: 1
        top_k:
          type: integer
          description: Top-K 采样参数
        stream:
          type: boolean
          description: 是否流式返回响应
          default: false
        stop_sequences:
          type: array
          description: 停止序列
          items:
            type: string
        tools:
          type: array
          description: 可用工具列表
          items:
            type: object
            properties:
              name:
                type: string
                description: 工具名称
              description:
                type: string
                description: 工具描述
              input_schema:
                type: object
                description: 工具输入参数的 JSON Schema
        tool_choice:
          type: object
          description: 工具选择策略
          properties:
            type:
              type: string
              description: 工具选择类型
              enum:
                - auto
                - any
                - tool
            name:
              type: string
              description: 指定工具名称（当 type 为 tool 时）
        metadata:
          type: object
          description: 请求元数据
          properties:
            user_id:
              type: string
              description: 用户标识符
    ClaudeMessagesResponse:
      type: object
      properties:
        id:
          type: string
          description: 唯一消息ID
          example: msg_abc123
        type:
          type: string
          description: 对象类型
          enum:
            - message
        role:
          type: string
          description: 角色
          enum:
            - assistant
        content:
          type: array
          description: 内容块列表
          items:
            type: object
            properties:
              type:
                type: string
                enum:
                  - text
              text:
                type: string
                example: Hello! How can I help you today?
        model:
          type: string
          description: 使用的模型
        stop_reason:
          type: string
          description: 生成停止原因
          enum:
            - end_turn
            - max_tokens
            - stop_sequence
            - tool_use
          example: end_turn
        usage:
          type: object
          description: 用量统计
          properties:
            input_tokens:
              type: integer
              description: 输入token数
              example: 25
            output_tokens:
              type: integer
              description: 输出token数
              example: 150
    ErrorResponse400:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 请求参数无效
            type:
              type: string
              example: invalid_request_error
    ErrorResponse401:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: API密钥无效
            type:
              type: string
              example: authentication_error
    ErrorResponse403:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 访问被拒绝
            type:
              type: string
              example: permission_error
    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: 服务器内部错误
            type:
              type: string
              example: server_error
  responses:
    ClaudeMessagesSuccess:
      description: Claude Messages API 响应
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ClaudeMessagesResponse'
    BadRequest:
      description: 请求错误
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Unauthorized:
      description: 未授权
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse401'
    PaymentRequired:
      description: 余额不足
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Forbidden:
      description: 禁止访问
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse403'
    TooManyRequests:
      description: 请求过多
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse429'
    InternalServerError:
      description: 服务器内部错误
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse500'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |
        ## 所有接口均需要使用Bearer Token进行认证 ##

        使用时在请求头中添加：

        `Authorization: Bearer YOUR_API_KEY`

````