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

# Anthropic 对话

> 接口说明：Anthropic Messages API（`/v1/messages`）的兼容端点，支持流式输出（SSE）。请求、响应与错误格式遵循 Anthropic 规范；鉴权使用 `x-api-key` 头（Anthropic SDK 默认携带），已有 Anthropic SDK 只需替换 baseURL 与 API Key 即可接入，按 AiToEarn 积分计费。

调用本接口前，请先请求[「对话模型列表」](/api-reference/get-api-ai-models-chat)接口（`GET /api/ai/models/chat`），获取当前可用的模型列表。



## OpenAPI

````yaml /openapi/zh/aitoearn.openapi.json post /api/ai/v1/messages
openapi: 3.0.1
info:
  title: AiToEarn 开放平台 API
  description: AiToEarn 开放平台 API，支持在中国站与国际站之间切换调试。业务是否成功以响应体 code === 0 为准。
  version: 1.0.0
  contact: {}
servers:
  - url: https://aitoearn.cn
    description: 中国站
  - url: https://aitoearn.ai
    description: 国际站
security: []
tags:
  - name: AI 服务
  - name: AI 服务/视频生成
  - name: AI 服务/图像生成
  - name: 渠道管理
  - name: 渠道管理/账号
  - name: 渠道管理/内容发布
  - name: 渠道管理/平台
  - name: 渠道管理/作品
  - name: 渠道管理/账号分组
  - name: 渠道管理/授权
  - name: 资源管理
  - name: AI 服务/大语言模型
  - name: AI 服务/真人素材
  - name: AI 服务/Agent
paths:
  /api/ai/v1/messages:
    post:
      tags:
        - AI 服务/大语言模型
      summary: Anthropic 对话
      description: >-
        接口说明：Anthropic Messages
        API（`/v1/messages`）的兼容端点，支持流式输出（SSE）。请求、响应与错误格式遵循 Anthropic 规范；鉴权使用
        `x-api-key` 头（Anthropic SDK 默认携带），已有 Anthropic SDK 只需替换 baseURL 与 API
        Key 即可接入，按 AiToEarn 积分计费。


        调用本接口前，请先请求[「对话模型列表」](/api-reference/get-api-ai-models-chat)接口（`GET
        /api/ai/models/chat`），获取当前可用的模型列表。
      operationId: RelayController_claudeMessages
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClaudeChatProxyDto'
            examples:
              '1':
                summary: 基础对话
                value:
                  model: claude-sonnet-5
                  messages:
                    - role: user
                      content: 请用一句话介绍 AiToEarn。
                  max_tokens: 64
        required: true
      responses:
        '200':
          description: 第三方协议原生响应或 SSE 数据。不使用 AiToEarn 通用响应包裹。
          content:
            text/event-stream:
              schema:
                type: string
                description: Anthropic Messages 协议的 SSE 事件流。
              examples:
                sse:
                  value: >-
                    event: message_start

                    data:
                    {"type":"message_start","message":{"model":"string","id":"string","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":"integer","output_tokens":"integer","cache_creation_input_tokens":"integer","cache_read_input_tokens":"integer"}}}


                    event: content_block_start

                    data:
                    {"type":"content_block_start","index":"integer","content_block":{"type":"text","text":"string"}}


                    event: content_block_delta

                    data:
                    {"type":"content_block_delta","index":"integer","delta":{"type":"text_delta","text":"string"}}


                    event: content_block_stop

                    data: {"type":"content_block_stop","index":"integer"}


                    event: message_delta

                    data:
                    {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":"integer","output_tokens":"integer","cache_creation_input_tokens":"integer","cache_read_input_tokens":"integer","cache_creation":{"ephemeral_5m_input_tokens":"integer"}}}


                    event: message_stop

                    data: {"type":"message_stop"}
      deprecated: false
      security:
        - apikey-header-X-Api-Key: []
components:
  schemas:
    ClaudeChatProxyDto:
      type: object
      properties:
        messages:
          minItems: 1
          type: array
          items:
            type: object
            properties:
              role:
                type: string
                enum:
                  - user
                  - assistant
                description: 消息角色，用于区分不同消息来源
                example: user
              content:
                description: 内容正文
                type: string
                example: 请用一句话介绍 AiToEarn。
            required:
              - role
              - content
            additionalProperties: true
          description: 消息列表
          example:
            - role: user
              content: 请用一句话介绍 AiToEarn。
        model:
          type: string
          description: >-
            Anthropic 渠道模型
            ID。先调用[「对话模型列表」](/api-reference/get-api-ai-models-chat)接口（`GET
            /api/ai/models/chat`），选择返回结果中 `channel` 为 `anthropic` 的
            `data[n].name`。
          example: claude-sonnet-5
        max_tokens:
          default: 32000
          type: integer
          minimum: 1
          maximum: 9007199254740991
          description: 最大输出 Token 数。取值范围为 1 至 9007199254740991，默认值为 32000；示例使用 64 以控制测试消耗。
          example: 64
      required:
        - messages
        - model
      additionalProperties: true
  securitySchemes:
    apikey-header-X-Api-Key:
      type: apiKey
      in: header
      name: X-Api-Key
      description: 需要从 AiToEarn 获取 API Key。点击前往[「API Key 获取教程」](/zh/use/api-key)。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.