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

# Anthropic Messages API

> Test BetterToken's Anthropic-compatible Messages API: x-api-key, anthropic-version, and POST /v1/messages.

`POST /v1/messages`

Use this endpoint for Claude Code, the Anthropic SDK, and applications that use the Anthropic Messages API.

<Note>
  For an SDK, use `https://bettertoken.ai` as the Base URL. A manual request and the Playground use the full `https://bettertoken.ai/v1/messages` path.
</Note>

## Test in the Playground

In the Playground on the right, enter your API Key in the `x-api-key` field, leave `anthropic-version` as `claude-cli/2.0.76 (external, cli)`, choose an available Claude provider model, and send the request.

<Warning>
  Do not use `Authorization: Bearer ...` for this endpoint. It requires the `x-api-key` header.
</Warning>

## Related endpoints

* [OpenAI Responses API](/en/api-reference/responses)
* [OpenAI Chat Completions API](/en/api-reference/chat-completions)


## OpenAPI

````yaml api-reference/openapi.json POST /v1/messages
openapi: 3.1.0
info:
  title: BetterToken GPT Image 2 API
  description: >-
    OpenAI-compatible image generation and image editing endpoints for
    BetterToken.
  version: 1.0.0
servers:
  - url: https://bettertoken.ai
security:
  - bearerAuth: []
paths:
  /v1/messages:
    post:
      tags:
        - Anthropic Messages
      summary: 创建 Anthropic Messages 响应
      description: >-
        通过 BetterToken 的 Anthropic-compatible Messages API 向 Claude
        提供商模型发送消息。适用于 Claude Code、Anthropic SDK 和使用 /v1/messages 的应用。
      operationId: createAnthropicMessage
      parameters:
        - name: anthropic-version
          in: header
          required: true
          description: Anthropic API version header.
          schema:
            type: string
            default: claude-cli/2.0.76 (external, cli)
            example: claude-cli/2.0.76 (external, cli)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AnthropicMessagesRequest'
            example:
              model: YOUR_MODEL_ID
              max_tokens: 1024
              messages:
                - role: user
                  content: Hello
      responses:
        '200':
          $ref: '#/components/responses/AnthropicMessageResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/ServerError'
      security:
        - anthropicApiKey: []
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl 'https://bettertoken.ai/v1/messages' \
              -H 'x-api-key: YOUR_API_KEY' \
              -H 'anthropic-version: claude-cli/2.0.76 (external, cli)' \
              -H 'content-type: application/json' \
              --data '{
                "model": "YOUR_MODEL_ID",
                "max_tokens": 1024,
                "messages": [{"role": "user", "content": "Hello"}]
              }'
components:
  schemas:
    AnthropicMessagesRequest:
      type: object
      required:
        - model
        - max_tokens
        - messages
      properties:
        model:
          type: string
          description: Claude 提供商中可用的模型 ID。
          example: YOUR_MODEL_ID
        max_tokens:
          type: integer
          minimum: 1
          description: 单次响应允许生成的最大 token 数。
          default: 1024
          example: 1024
        messages:
          type: array
          minItems: 1
          description: Anthropic 格式的消息数组。每项应包含 role 和 content。
          items:
            type: object
            required:
              - role
              - content
            properties:
              role:
                type: string
                example: user
              content:
                type: string
                example: Hello
            additionalProperties: true
      additionalProperties: true
    AnthropicMessageResponse:
      type: object
      description: Anthropic-compatible Messages API 响应。实际字段会随所选模型和请求参数变化。
      additionalProperties: true
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: invalid request
            type:
              type: string
              example: invalid_request_error
            code:
              type: string
              example: invalid_request
          additionalProperties: true
        message:
          type: string
          example: insufficient quota
      additionalProperties: true
  responses:
    AnthropicMessageResponse:
      description: Claude 提供商模型返回的 Anthropic Messages API 响应。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AnthropicMessageResponse'
    BadRequest:
      description: 请求格式错误、缺少参数、JSON 或 multipart 解析失败、尺寸格式错误。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: API Key 缺失或无效。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    PaymentRequired:
      description: 额度或余额不足。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    RateLimited:
      description: 触发限速、并发限制或上游繁忙。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    ServerError:
      description: 网关或上游服务异常。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: BetterToken API Key
      description: >-
        Use your BetterToken API Key as a bearer token. Do not expose API keys
        in frontend browser code, screenshots, logs, tickets, or Git
        repositories.
    anthropicApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Use your BetterToken API Key in the x-api-key header for
        Anthropic-compatible requests.

````