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

# Anthropic Messages

> Send a message to the Anthropic models. Supports streaming and non-streaming responses.

Send a message to Anthropic models using the native Anthropic Messages API format. Supports streaming and non-streaming responses.

## Create Anthropic Message

To create an Anthropic message, use the following endpoint:

`POST /v1/messages`

<Info>
  This endpoint is compatible with the Anthropic SDK (`anthropic` Python/Node.js package). Point
  your SDK at `https://api.routeway.ai` and replace your Anthropic API key with your Routeway
  key — no other changes needed.
</Info>

### Request Body

<ParamField body="model" type="string" required>
  The Anthropic model ID to use (e.g. `"claude-opus-4-5"`, `"claude-sonnet-4-5"`). See
  [Models](/getting-started/models) for the full list of supported Anthropic models.
</ParamField>

<ParamField body="messages" type="array" required>
  An array of message objects forming the conversation. Each object must have a `role`
  (`"user"` or `"assistant"`) and a `content` field (string or array of content blocks).
</ParamField>

<ParamField body="max_tokens" type="integer" required>
  The maximum number of tokens to generate before stopping.
</ParamField>

<ParamField body="system" type="string | array">
  A system prompt that provides context and instructions to the model. Can be a plain string
  or an array of content blocks.
</ParamField>

<ParamField body="temperature" type="number">
  Sampling temperature between 0 and 1. Higher values produce more varied outputs.
</ParamField>

<ParamField body="stream" type="boolean">
  Whether to stream the response as Server-Sent Events (SSE).
</ParamField>

<ParamField body="stop_sequences" type="array">
  Custom text sequences that will cause the model to stop generating.
</ParamField>

<ParamField body="tools" type="array">
  A list of tools the model may call. Each tool must have a `name`, optional `description`,
  and an `input_schema` (JSON Schema object).
</ParamField>

<ParamField body="tool_choice" type="object">
  Controls tool use. Can be `{"type": "auto"}`, `{"type": "any"}`, or
  `{"type": "tool", "name": "..."}`.
</ParamField>

<ParamField body="top_p" type="number">
  Nucleus sampling parameter. Use `temperature` or `top_p`, but not both.
</ParamField>

<ParamField body="top_k" type="integer">
  Only sample from the top K options for each subsequent token.
</ParamField>

<RequestExample>
  ```python Python theme={null}
  import os
  import anthropic

  client = anthropic.Anthropic(
      base_url="https://api.routeway.ai",
      api_key=os.getenv("ROUTEWAY_API_KEY")
  )

  message = client.messages.create(
      model="claude-opus-4-5",
      max_tokens=1024,
      messages=[
          {"role": "user", "content": "Hello, Claude!"}
      ]
  )

  print(message.content[0].text)
  ```

  ```javascript Node.js theme={null}
  import Anthropic from "@anthropic-ai/sdk";

  const client = new Anthropic({
    baseURL: "https://api.routeway.ai",
    apiKey: process.env.ROUTEWAY_API_KEY,
  });

  const message = await client.messages.create({
    model: "claude-opus-4-5",
    max_tokens: 1024,
    messages: [{ role: "user", content: "Hello, Claude!" }],
  });

  console.log(message.content[0].text);
  ```

  ```bash cURL theme={null}
  curl https://api.routeway.ai/v1/messages \
    -H "Authorization: Bearer $ROUTEWAY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "claude-opus-4-5",
      "max_tokens": 1024,
      "messages": [
        {"role": "user", "content": "Hello, Claude!"}
      ]
    }'
  ```
</RequestExample>


## OpenAPI

````yaml POST /v1/messages
openapi: 3.1.0
info:
  title: Routeway API
  version: 1.0.0
servers:
  - url: https://api.routeway.ai
security:
  - HTTPBearer: []
paths:
  /v1/messages:
    post:
      tags:
        - Anthropic Messages
      summary: Create Anthropic Message (v1)
      description: >-
        Send a message to the Anthropic models. Supports streaming and
        non-streaming responses.
      operationId: anthropic_messages_v1_messages_post
      parameters:
        - name: x-api-key
          in: header
          required: false
          schema:
            type: string
            title: X-Api-Key
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MessagesRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessagesResponse'
        '400':
          description: Bad Request - Invalid query parameters or body format.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized - Missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Forbidden - Key does not have permission or is disabled.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Unprocessable Entity - Request body validation failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Too Many Requests - Rate limit exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal Server Error - Internal error occurred.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '502':
          description: Bad Gateway - Provider error occurred.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    MessagesRequest:
      properties:
        model:
          type: string
          title: Model
        max_tokens:
          type: integer
          exclusiveMinimum: 0
          title: Max Tokens
        messages:
          items:
            $ref: '#/components/schemas/Message-Input'
          type: array
          title: Messages
        system:
          anyOf:
            - type: string
            - items:
                anyOf:
                  - $ref: '#/components/schemas/TextBlock'
                  - $ref: '#/components/schemas/ImageBlock'
                  - $ref: '#/components/schemas/DocumentBlock'
                  - $ref: '#/components/schemas/ToolUseBlock'
                  - $ref: '#/components/schemas/ToolResultBlock'
              type: array
            - type: 'null'
          title: System
        stream:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Stream
          default: false
        temperature:
          anyOf:
            - type: number
              maximum: 2
              minimum: 0
            - type: 'null'
          title: Temperature
        top_p:
          anyOf:
            - type: number
              maximum: 1
              minimum: 0
            - type: 'null'
          title: Top P
        top_k:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
          title: Top K
        stop_sequences:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Stop Sequences
        tools:
          anyOf:
            - items:
                $ref: '#/components/schemas/ToolDefinition'
              type: array
            - type: 'null'
          title: Tools
        tool_choice:
          anyOf:
            - $ref: '#/components/schemas/ToolChoiceAuto'
            - $ref: '#/components/schemas/ToolChoiceNone'
            - $ref: '#/components/schemas/ToolChoiceAny'
            - $ref: '#/components/schemas/ToolChoiceSpecific'
            - type: 'null'
          title: Tool Choice
        disable_parallel_tool_use:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Disable Parallel Tool Use
        thinking:
          anyOf:
            - oneOf:
                - $ref: '#/components/schemas/ThinkingConfigEnabled'
                - $ref: '#/components/schemas/ThinkingConfigDisabled'
                - $ref: '#/components/schemas/ThinkingConfigAdaptive'
              discriminator:
                propertyName: type
                mapping:
                  adaptive:
                    $ref: '#/components/schemas/ThinkingConfigAdaptive'
                  disabled:
                    $ref: '#/components/schemas/ThinkingConfigDisabled'
                  enabled:
                    $ref: '#/components/schemas/ThinkingConfigEnabled'
            - type: 'null'
          title: Thinking
        metadata:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Metadata
      type: object
      required:
        - model
        - max_tokens
        - messages
      title: MessagesRequest
    MessagesResponse:
      properties:
        id:
          type: string
          title: Id
        type:
          type: string
          const: message
          title: Type
          default: message
        role:
          type: string
          const: assistant
          title: Role
          default: assistant
        model:
          type: string
          title: Model
        content:
          items:
            anyOf:
              - $ref: '#/components/schemas/TextBlock'
              - $ref: '#/components/schemas/ImageBlock'
              - $ref: '#/components/schemas/DocumentBlock'
              - $ref: '#/components/schemas/ToolUseBlock'
              - $ref: '#/components/schemas/ToolResultBlock'
          type: array
          title: Content
        stop_reason:
          type: string
          enum:
            - end_turn
            - max_tokens
            - stop_sequence
            - tool_use
            - content_filter
          title: Stop Reason
        stop_sequence:
          anyOf:
            - type: string
            - type: 'null'
          title: Stop Sequence
        usage:
          $ref: '#/components/schemas/schemas__anthropic__Usage'
      type: object
      required:
        - id
        - model
        - content
        - stop_reason
        - usage
      title: MessagesResponse
    ErrorResponse:
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetail'
      type: object
      required:
        - error
      title: ErrorResponse
    Message-Input:
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
          title: Role
        content:
          anyOf:
            - type: string
            - items:
                anyOf:
                  - $ref: '#/components/schemas/TextBlock'
                  - $ref: '#/components/schemas/ImageBlock'
                  - $ref: '#/components/schemas/DocumentBlock'
                  - $ref: '#/components/schemas/ToolUseBlock'
                  - $ref: '#/components/schemas/ToolResultBlock'
              type: array
          title: Content
      type: object
      required:
        - role
        - content
      title: Message
    TextBlock:
      properties:
        type:
          type: string
          const: text
          title: Type
          default: text
        text:
          type: string
          title: Text
        cache_control:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Cache Control
      type: object
      required:
        - text
      title: TextBlock
    ImageBlock:
      properties:
        type:
          type: string
          const: image
          title: Type
          default: image
        source:
          $ref: '#/components/schemas/ImageSource'
      type: object
      required:
        - source
      title: ImageBlock
    DocumentBlock:
      properties:
        type:
          type: string
          const: document
          title: Type
          default: document
        source:
          $ref: '#/components/schemas/DocumentSource'
      type: object
      required:
        - source
      title: DocumentBlock
    ToolUseBlock:
      properties:
        type:
          type: string
          const: tool_use
          title: Type
          default: tool_use
        id:
          type: string
          title: Id
        name:
          type: string
          title: Name
        input:
          additionalProperties: true
          type: object
          title: Input
      type: object
      required:
        - id
        - name
        - input
      title: ToolUseBlock
    ToolResultBlock:
      properties:
        type:
          type: string
          const: tool_result
          title: Type
          default: tool_result
        tool_use_id:
          type: string
          title: Tool Use Id
        content:
          anyOf:
            - type: string
            - items:
                additionalProperties: true
                type: object
              type: array
          title: Content
        is_error:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Is Error
          default: false
      type: object
      required:
        - tool_use_id
        - content
      title: ToolResultBlock
    ToolDefinition:
      properties:
        name:
          type: string
          pattern: ^[a-zA-Z0-9_-]{1,64}$
          title: Name
        description:
          type: string
          title: Description
        input_schema:
          $ref: '#/components/schemas/ToolInputSchema'
        input_examples:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Input Examples
        cache_control:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Cache Control
        strict:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Strict
        defer_loading:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Defer Loading
        allowed_callers:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Allowed Callers
      type: object
      required:
        - name
        - description
        - input_schema
      title: ToolDefinition
    ToolChoiceAuto:
      properties:
        type:
          type: string
          const: auto
          title: Type
          default: auto
      type: object
      title: ToolChoiceAuto
    ToolChoiceNone:
      properties:
        type:
          type: string
          const: none
          title: Type
          default: none
      type: object
      title: ToolChoiceNone
    ToolChoiceAny:
      properties:
        type:
          type: string
          const: any
          title: Type
          default: any
      type: object
      title: ToolChoiceAny
    ToolChoiceSpecific:
      properties:
        type:
          type: string
          const: tool
          title: Type
          default: tool
        name:
          type: string
          title: Name
      type: object
      required:
        - name
      title: ToolChoiceSpecific
    ThinkingConfigEnabled:
      properties:
        type:
          type: string
          const: enabled
          title: Type
          default: enabled
        budget_tokens:
          type: integer
          minimum: 1024
          title: Budget Tokens
      type: object
      required:
        - budget_tokens
      title: ThinkingConfigEnabled
    ThinkingConfigDisabled:
      properties:
        type:
          type: string
          const: disabled
          title: Type
          default: disabled
      type: object
      title: ThinkingConfigDisabled
    ThinkingConfigAdaptive:
      properties:
        type:
          type: string
          const: adaptive
          title: Type
          default: adaptive
        budget_tokens:
          anyOf:
            - type: integer
              minimum: 1024
            - type: 'null'
          title: Budget Tokens
      type: object
      title: ThinkingConfigAdaptive
    schemas__anthropic__Usage:
      properties:
        input_tokens:
          type: integer
          title: Input Tokens
        output_tokens:
          type: integer
          title: Output Tokens
        cache_creation_input_tokens:
          type: integer
          title: Cache Creation Input Tokens
          default: 0
        cache_read_input_tokens:
          type: integer
          title: Cache Read Input Tokens
          default: 0
        cache_creation:
          anyOf:
            - $ref: '#/components/schemas/CacheCreation'
            - type: 'null'
        service_tier:
          anyOf:
            - type: string
              enum:
                - standard
                - priority
            - type: 'null'
          title: Service Tier
          default: standard
      type: object
      required:
        - input_tokens
        - output_tokens
      title: Usage
    ErrorDetail:
      properties:
        message:
          type: string
          title: Message
          description: A human-readable description of the error.
        type:
          type: string
          title: Type
          description: >-
            The type of error returned (e.g. invalid_request_error,
            rate_limit_error).
        param:
          anyOf:
            - type: string
            - type: 'null'
          title: Param
          description: The parameter that caused the error, if applicable.
        code:
          anyOf:
            - type: string
            - type: 'null'
          title: Code
          description: >-
            A short code identifier for the error type (e.g. invalid_request,
            rate_limit).
        status_code:
          type: integer
          title: Status Code
          description: The HTTP status code.
        id:
          type: string
          title: Id
          description: Unique error or trace ID associated with this request.
        tip:
          anyOf:
            - type: string
            - type: 'null'
          title: Tip
          description: An optional troubleshooting tip or resolution suggestion.
        docs:
          anyOf:
            - type: string
            - type: 'null'
          title: Docs
          description: Link to the documentation related to this error.
          default: https://docs.routeway.ai
        support:
          anyOf:
            - type: string
            - type: 'null'
          title: Support
          description: Link to support for further help.
          default: https://discord.gg/RjX2CpdPpd
        community:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Community
          description: Links to community resources like Discord and Twitter.
      type: object
      required:
        - message
        - type
        - status_code
        - id
      title: ErrorDetail
    ImageSource:
      properties:
        type:
          type: string
          enum:
            - base64
            - url
          title: Type
        media_type:
          type: string
          enum:
            - image/jpeg
            - image/png
            - image/gif
            - image/webp
          title: Media Type
        data:
          anyOf:
            - type: string
            - type: 'null'
          title: Data
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
      type: object
      required:
        - type
        - media_type
      title: ImageSource
    DocumentSource:
      properties:
        type:
          type: string
          enum:
            - base64
            - url
          title: Type
        media_type:
          type: string
          const: application/pdf
          title: Media Type
        data:
          anyOf:
            - type: string
            - type: 'null'
          title: Data
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
      type: object
      required:
        - type
        - media_type
      title: DocumentSource
    ToolInputSchema:
      properties:
        type:
          type: string
          const: object
          title: Type
          default: object
        properties:
          additionalProperties:
            $ref: '#/components/schemas/ToolParameter'
          type: object
          title: Properties
        required:
          items:
            type: string
          type: array
          title: Required
          default: []
      type: object
      required:
        - properties
      title: ToolInputSchema
    CacheCreation:
      properties:
        ephemeral_5m_input_tokens:
          type: integer
          title: Ephemeral 5M Input Tokens
          default: 0
        ephemeral_1h_input_tokens:
          type: integer
          title: Ephemeral 1H Input Tokens
          default: 0
      type: object
      title: CacheCreation
    ToolParameter:
      properties:
        type:
          anyOf:
            - type: string
              enum:
                - string
                - number
                - boolean
                - object
                - array
                - integer
                - 'null'
            - type: 'null'
          title: Type
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        enum:
          anyOf:
            - items: {}
              type: array
            - type: 'null'
          title: Enum
        items:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Items
        properties:
          anyOf:
            - additionalProperties:
                $ref: '#/components/schemas/ToolParameter'
              type: object
            - type: 'null'
          title: Properties
        required:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Required
        minimum:
          anyOf:
            - type: integer
            - type: number
            - type: 'null'
          title: Minimum
        maximum:
          anyOf:
            - type: integer
            - type: number
            - type: 'null'
          title: Maximum
        min_length:
          anyOf:
            - type: integer
            - type: 'null'
          title: Min Length
        max_length:
          anyOf:
            - type: integer
            - type: 'null'
          title: Max Length
        pattern:
          anyOf:
            - type: string
            - type: 'null'
          title: Pattern
        format:
          anyOf:
            - type: string
            - type: 'null'
          title: Format
        default:
          anyOf:
            - {}
            - type: 'null'
          title: Default
        nullable:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Nullable
        additional_properties:
          anyOf:
            - type: boolean
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Additional Properties
      type: object
      title: ToolParameter
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````