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

# Messages

> Send an Anthropic-compatible Messages request to a Relace-hosted model.

Anthropic-compatible endpoint for open-weights models hosted on Relace infrastructure. You can also use this by pointing any Anthropic SDK at `https://models.relace.ai` with your Relace API key. The same models, pricing, and servers back [Chat Completions](/api-reference/open-models/chat-completions); pick whichever dialect your client already speaks.

## Models

| Model                  | `model` ID                           | Context | Input       | Output      | Cached Input |
| ---------------------- | ------------------------------------ | ------- | ----------- | ----------- | ------------ |
| DeepSeek V4 Flash 0731 | `deepseek-ai/DeepSeek-V4-Flash-0731` | 1M      | \$0.065 / M | \$0.18 / M  | \$0.016 / M  |
| Kimi K3                | `moonshotai/kimi-k3`                 | 1M      | \$3.00 / M  | \$15.00 / M | \$0.30 / M   |
| GLM 5.3 Flash          | `z-ai/glm-5.3-flash`                 | 1M      | \$0.075 / M | \$0.25 / M  | \$0.015 / M  |

See the [Open Models guide](/docs/open-models/quickstart#anthropic-compatible-api) for SDK examples and streaming.

## Authentication

The key goes in either header, as your client prefers:

* `x-api-key: <key>` -- what the Anthropic SDKs send.
* `Authorization: Bearer <key>` -- the same header as every other Relace endpoint.

`anthropic-version` is accepted and ignored.

## Prompt Caching

Prompt caching is automatic and needs no `cache_control` markers; any you send are accepted and ignored. Cache hits are billed at the Cached Input rate and reported in `usage.cache_read_input_tokens`, with `usage.input_tokens` counting only the uncached remainder. `cache_creation_input_tokens` is always `0`: writing to the cache is free.

To keep a multi-turn session on its cache, set `metadata.user_id` to a stable value per session; it plays the role `prompt_cache_key` does on Chat Completions. See [Prompt Caching and Session Affinity](/docs/open-models/quickstart#prompt-caching-and-session-affinity).

## Extended Thinking

`thinking: {"type": "enabled"}` or `"adaptive"` turns a model's reasoning on and `"disabled"` turns it off; `budget_tokens` is accepted but the models do not enforce a budget. Reasoning comes back as `thinking` content blocks (and `thinking_delta` events when streaming) with an empty `signature`. Reasoning tokens count toward `max_tokens`.

## Differences from Anthropic

The request and response shapes follow the [Anthropic Messages API](https://docs.anthropic.com/en/api/messages), with these exceptions:

* **Content**: `text`, `image` (base64 or URL), `tool_use`, `tool_result`, and `thinking` blocks are supported. `document` blocks, Files API references, and search results return `400`.
* **Tools**: client tools with an `input_schema` are supported, including `disable_parallel_tool_use`. `tool_choice` of `any` or a named tool is honored by models that support forced tool choice (`forced_tool_choice` in the model's `supported_features` from `GET /models`) and served as `auto` by the rest. Anthropic's server tools (web search, code execution, computer use, etc.) are ignored.
* **Structured output**: `output_config.format` is accepted and ignored by the models above; none constrain output to a schema. `output_config.effort` maps onto the model's reasoning effort levels where it has them.
* **`stop_sequence`**: reported when the model identifies the matched sequence; otherwise `stop_reason` is `end_turn`.
* **Not served**: `/v1/messages/count_tokens`, the Batches API, and the Files API.


## OpenAPI

````yaml POST /v1/messages
openapi: 3.0.1
info:
  title: Relace API
  description: API for accessing Relace code generation models.
  version: 1.0.0
  license:
    name: MIT
servers:
  - url: https://models.relace.ai
    description: Server for model API endpoints
  - url: https://api.relace.run
    description: Server for general infrastructure
security:
  - bearerAuth: []
paths:
  /v1/messages:
    post:
      description: Send an Anthropic-compatible Messages request to a Relace-hosted model.
      requestBody:
        description: Anthropic-compatible Messages request
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MessagesRequest'
            example:
              model: deepseek-ai/DeepSeek-V4-Flash-0731
              max_tokens: 1024
              messages:
                - role: user
                  content: Write a binary search in Python.
              stream: false
      responses:
        '200':
          description: Message generated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessagesResponse'
            text/event-stream:
              schema:
                type: string
                description: >-
                  Stream of Anthropic Messages events: `message_start`, then
                  `content_block_start` / `content_block_delta` /
                  `content_block_stop` per content block, then `message_delta`
                  with the stop reason and token usage, then `message_stop`.
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '402':
          description: Out of credits, or no payment method on the account
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '404':
          description: Route not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '429':
          description: Rate limit exceeded, or the model is at capacity
          headers:
            Retry-After:
              schema:
                type: string
              description: Seconds to wait before retrying
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '502':
          description: Model server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '503':
          description: Model temporarily unavailable
          headers:
            Retry-After:
              schema:
                type: string
              description: Seconds to wait before retrying
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '504':
          description: Request to the model timed out
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
      security:
        - apiKeyAuth: []
        - bearerAuth: []
      servers:
        - url: https://models.relace.ai
components:
  schemas:
    MessagesRequest:
      type: object
      required:
        - model
        - max_tokens
        - messages
      properties:
        model:
          type: string
          description: >-
            ID of the hosted model to use, e.g.
            `deepseek-ai/DeepSeek-V4-Flash-0731` or `moonshotai/kimi-k3`.
        max_tokens:
          type: integer
          description: >-
            Maximum number of tokens to generate. Reasoning tokens count toward
            this limit, so set a generous budget.
        messages:
          type: array
          items:
            type: object
          description: >-
            The conversation so far, as Anthropic-format message objects with
            `role` (`user` or `assistant`) and `content` (a string, or an array
            of `text`, `image`, `tool_use`, `tool_result`, and `thinking`
            blocks).
        system:
          description: System prompt, as a string or an array of `text` blocks.
        stream:
          type: boolean
          description: >-
            If true, the response is sent as server-sent events in the Anthropic
            streaming format. Token usage is reported in the `message_delta`
            event.
        temperature:
          type: number
          description: Sampling temperature. Higher values make output more random.
        top_p:
          type: number
          description: >-
            Nucleus sampling: only tokens within the top `top_p` probability
            mass are considered.
        top_k:
          type: integer
          description: Only the `top_k` most likely tokens are considered at each step.
        stop_sequences:
          type: array
          items:
            type: string
          description: Up to 4 sequences at which generation stops.
        tools:
          type: array
          items:
            type: object
          description: >-
            Anthropic-format tool definitions with `name`, `description`, and
            `input_schema`. Server tools are ignored.
        tool_choice:
          type: object
          description: >-
            Controls tool use: `{"type": "auto"}`, `{"type": "any"}`, `{"type":
            "tool", "name": ...}`, or `{"type": "none"}`. `any` and a named tool
            require a model with forced tool choice; others are served as
            `auto`. Set `disable_parallel_tool_use` to limit the model to one
            call per turn.
        thinking:
          type: object
          description: >-
            `{"type": "enabled"}` or `{"type": "adaptive"}` turns reasoning on;
            `{"type": "disabled"}` turns it off. `budget_tokens` is accepted but
            not enforced.
        output_config:
          type: object
          description: >-
            `effort` (`low` to `max`) maps onto the model's reasoning effort
            levels where it has them. `format` is accepted and ignored.
        metadata:
          type: object
          properties:
            user_id:
              type: string
              maxLength: 512
              description: >-
                Cache affinity key. Requests with the same value are served by
                the same server, improving cache hit rates for multi-turn
                sessions. Use a stable value per conversation or session.
      additionalProperties: true
      description: >-
        Anthropic-compatible request. `cache_control` markers and other
        Anthropic-only fields are accepted and ignored. Supported sampling
        parameters vary slightly by model.
    MessagesResponse:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier for the message, prefixed `msg_`
        type:
          type: string
          description: Always `message`
        role:
          type: string
          description: Always `assistant`
        model:
          type: string
          description: The model that served the request
        content:
          type: array
          items:
            type: object
          description: >-
            The generated content blocks, in order: `thinking` (when reasoning
            is on), `text`, and `tool_use` (with the call's `id`, `name`, and
            parsed `input`)
        stop_reason:
          type: string
          description: >-
            Why generation stopped: `end_turn`, `max_tokens`, `stop_sequence`,
            or `tool_use`
        stop_sequence:
          type: string
          nullable: true
          description: >-
            The matched stop sequence when `stop_reason` is `stop_sequence`;
            otherwise null
        usage:
          type: object
          properties:
            input_tokens:
              type: integer
              description: Prompt tokens not served from cache
            cache_read_input_tokens:
              type: integer
              description: Prompt tokens served from cache, billed at the Cached Input rate
            cache_creation_input_tokens:
              type: integer
              description: Always 0; writing to the cache is free
            output_tokens:
              type: integer
              description: Tokens generated, including reasoning
          description: Token usage information for the request
    AnthropicError:
      type: object
      properties:
        type:
          type: string
          description: Always `error`
          example: error
        error:
          type: object
          properties:
            type:
              type: string
              description: Anthropic error type
              enum:
                - invalid_request_error
                - authentication_error
                - billing_error
                - permission_error
                - not_found_error
                - request_too_large
                - rate_limit_error
                - api_error
                - overloaded_error
                - timeout_error
              example: rate_limit_error
            message:
              type: string
              description: Error message
              example: >-
                Rate limit exceeded. Retry after the Retry-After interval, or
                contact support to raise your limits.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Relace API key Authorization header using the Bearer scheme.
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Relace API key in the `x-api-key` header, as the Anthropic SDKs send it.
        Accepted on `/v1/messages` only.

````