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

# Messages

> Tokenless accepts the compatible Anthropic Messages request shape and
routes the request behind a Tokenless routing profile. For the complete
upstream contract, see the [Claude Messages API reference](https://platform.claude.com/docs/en/api/messages/create).


<div className="endpoint-signature"><span className="endpoint-method endpoint-method-post">POST</span><code>/anthropic/v1/messages</code></div>

For the full upstream contract, see the [Claude Messages API reference](https://platform.claude.com/docs/en/api/messages/create).

<RequestExample>
  ```bash cURL
  curl https://api.usetokenless.com/anthropic/v1/messages \
    -H "x-api-key: $TOKENLESS_API_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "tokenless-pro",
      "max_tokens": 1024,
      "messages": [
        {"role": "user", "content": "Explain model routing in one paragraph."}
      ],
      "stream": true
    }'
  ```
</RequestExample>

<ResponseExample>
  ```sse Stream (abridged)
  event: message_start
  data: {"message":{"content":[],"id":"msg_req_1e6255bf_5d10049d4ab0_1","model":"deepseek-v4-flash","role":"assistant","stop_reason":null,"stop_sequence":null,"type":"message","usage":{"input_tokens":0,"output_tokens":0}},"type":"message_start"}

  event: content_block_start
  data: {"content_block":{"thinking":"","type":"thinking"},"index":0,"type":"content_block_start"}

  event: content_block_delta
  data: {"delta":{"thinking":"We","type":"thinking_delta"},"index":0,"type":"content_block_delta"}

  : intermediate thinking deltas omitted

  event: content_block_stop
  data: {"index":0,"type":"content_block_stop"}

  event: content_block_start
  data: {"content_block":{"text":"","type":"text"},"index":1,"type":"content_block_start"}

  event: content_block_delta
  data: {"delta":{"text":"Model routing is the process of intelligently directing a user's request to the most suitable AI model…","type":"text_delta"},"index":1,"type":"content_block_delta"}

  event: content_block_stop
  data: {"index":1,"type":"content_block_stop"}

  event: message_delta
  data: {"delta":{"stop_reason":"end_turn","stop_sequence":null},"type":"message_delta","usage":{"input_tokens":11,"output_tokens":227}}

  event: message_stop
  data: {"type":"message_stop"}
  ```
</ResponseExample>


## OpenAPI

````yaml /openapi/compatibility.yaml post /anthropic/v1/messages
openapi: 3.1.0
info:
  title: Tokenless Compatibility and BYOK API
  version: 1.0.0
  description: |
    OpenAI- and Anthropic-compatible routing endpoints, plus interactive-session
    management for bring-your-own provider keys.
servers:
  - url: https://api.usetokenless.com
security:
  - tokenlessBearer: []
paths:
  /anthropic/v1/messages:
    post:
      tags:
        - Anthropic
      summary: Messages
      description: >
        Tokenless accepts the compatible Anthropic Messages request shape and

        routes the request behind a Tokenless routing profile. For the complete

        upstream contract, see the [Claude Messages API
        reference](https://platform.claude.com/docs/en/api/messages/create).
      operationId: createMessage
      parameters:
        - $ref: '#/components/parameters/AnthropicVersion'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AnthropicMessageRequest'
            example:
              model: tokenless-pro
              max_tokens: 1024
              messages:
                - role: user
                  content: Explain model routing in one paragraph.
              stream: true
      responses:
        '200':
          description: An Anthropic-compatible message response or SSE stream.
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestID'
        '400':
          $ref: '#/components/responses/AnthropicError'
        '401':
          $ref: '#/components/responses/AnthropicError'
        '402':
          $ref: '#/components/responses/AnthropicError'
      security:
        - anthropicAPIKey: []
      x-codeSamples:
        - lang: bash
          label: cURL
          source: |
            curl https://api.usetokenless.com/anthropic/v1/messages \
              -H "x-api-key: $TOKENLESS_API_KEY" \
              -H "anthropic-version: 2023-06-01" \
              -H "Content-Type: application/json" \
              -d '{
                "model": "tokenless-pro",
                "max_tokens": 1024,
                "messages": [
                  {"role": "user", "content": "Explain model routing in one paragraph."}
                ],
                "stream": true
              }'
components:
  parameters:
    AnthropicVersion:
      name: anthropic-version
      in: header
      required: true
      schema:
        type: string
      example: '2023-06-01'
      description: Selects the Anthropic-compatible response format.
  schemas:
    AnthropicMessageRequest:
      type: object
      required:
        - model
        - max_tokens
        - messages
      properties:
        model:
          $ref: '#/components/schemas/RoutingProfile'
        max_tokens:
          type: integer
          minimum: 1
        messages:
          type: array
          minItems: 1
          items:
            type: object
            additionalProperties: true
        stream:
          type: boolean
          default: false
      additionalProperties: true
    RoutingProfile:
      type: string
      enum:
        - tokenless-pro
        - tokenless-max
        - tokenless-ultra-saver
    AnthropicError:
      type: object
      properties:
        type:
          type: string
        error:
          type: object
          additionalProperties: true
  headers:
    RequestID:
      description: Identifier for the routed request. Save it for support and usage lookup.
      schema:
        type: string
  responses:
    AnthropicError:
      description: Anthropic-compatible error response.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AnthropicError'
  securitySchemes:
    tokenlessBearer:
      type: http
      scheme: bearer
      bearerFormat: Tokenless API key
    anthropicAPIKey:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Tokenless API key. Include `anthropic-version` on Anthropic-compatible
        requests.

````