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

# Crun Anthropic Messages API

> Anthropic-compatible /messages endpoint for CRUN language models, supporting Claude-style messages, system prompts, vision content blocks, tools, thinking, and streaming events.

## API Endpoint

```text theme={null}
POST https://api.crun.ai/api/v1/messages
```

<Info>
  This endpoint follows the [Anthropic Messages](https://platform.claude.com/docs/en/api/python/messages/create) API request and response shape.
  It is designed for Claude-compatible clients while using your CRUN API key and CRUN public model IDs.
</Info>

## Authentication

You can authenticate with either:

* `Authorization: Bearer YOUR_API_KEY`
* `X-API-KEY: YOUR_API_KEY`

Optional Anthropic request headers such as `anthropic-version` and `anthropic-beta` are accepted and forwarded upstream when provided.

## Basic Message

<CodeGroup>
  ```bash cURL theme={null} theme={null}
  curl -X POST "https://api.crun.ai/api/v1/messages" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -H "anthropic-version: 2023-06-01" \
    -d '{
      "model": "claude-sonnet-4-6",
      "max_tokens": 512,
      "messages": [
        {
          "role": "user",
          "content": "Write a concise project update for a payments API migration."
        }
      ]
    }'
  ```

  ```python Python (Anthropic SDK) theme={null} theme={null}
  from anthropic import Anthropic

  client = Anthropic(
      api_key="YOUR_API_KEY",
      base_url="https://api.crun.ai/api",
  )

  message = client.messages.create(
      model="claude-sonnet-4-6",
      max_tokens=512,
      messages=[
          {
              "role": "user",
              "content": "Write a concise project update for a payments API migration.",
          }
      ],
  )

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

  ```javascript JavaScript (Anthropic SDK) theme={null} theme={null}
  import Anthropic from "@anthropic-ai/sdk";

  const client = new Anthropic({
    apiKey: "YOUR_API_KEY",
    baseURL: "https://api.crun.ai/api"
  });

  const message = await client.messages.create({
    model: "claude-sonnet-4-6",
    max_tokens: 512,
    messages: [
      {
        role: "user",
        content: "Write a concise project update for a payments API migration."
      }
    ]
  });

  console.log(message.content[0].text);
  ```
</CodeGroup>

## System Prompt

Anthropic Messages uses a top-level `system` field instead of a `system` role in the `messages` array.

```json request body theme={null} theme={null}
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 800,
  "system": "You are a senior API documentation editor. Be concise and precise.",
  "messages": [
    {
      "role": "user",
      "content": "Rewrite this changelog entry for developers: fixed auth bug."
    }
  ]
}
```

## Conversation History

CRUN does not store conversation state for `/messages`. To continue a conversation, include the prior user and assistant turns in the next request.

```json request body theme={null} theme={null}
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 800,
  "messages": [
    {
      "role": "user",
      "content": "Give me three names for an internal developer newsletter."
    },
    {
      "role": "assistant",
      "content": "Here are three options: Build Notes, Ship Log, and Dev Dispatch."
    },
    {
      "role": "user",
      "content": "Make them sound more enterprise-ready."
    }
  ]
}
```

## Vision Input

When the selected model supports vision, pass a content array with `text` and `image` blocks. Image sources can use a URL/file source.

<CodeGroup>
  ```json URL image theme={null} theme={null}
  {
    "model": "claude-sonnet-4-6",
    "max_tokens": 800,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Summarize the product shown in this image."
          },
          {
            "type": "image",
            "source": {
              "type": "url",
              "url": "https://example.com/product-photo.png"
            }
          }
        ]
      }
    ]
  }
  ```
</CodeGroup>

## Tool Use

Pass `tools` to let the model request structured function calls. Your application executes the tool and sends the result back in a follow-up message.

```json request body theme={null} theme={null}
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "What is the weather in Paris?"
    }
  ],
  "tools": [
    {
      "name": "get_weather",
      "description": "Get current weather for a city.",
      "input_schema": {
        "type": "object",
        "properties": {
          "city": {
            "type": "string"
          }
        },
        "required": ["city"]
      }
    }
  ],
  "tool_choice": {
    "type": "auto"
  }
}
```

## Thinking

When supported by the selected model and upstream provider, use `thinking` to request extended reasoning behavior.

```json request body theme={null} theme={null}
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 2048,
  "thinking": {
    "type": "enabled",
    "budget_tokens": 1024
  },
  "messages": [
    {
      "role": "user",
      "content": "Compare two API migration plans and recommend the lower-risk option."
    }
  ]
}
```

## Streaming

Set `stream=true` to receive Anthropic-style Server-Sent Events.

<CodeGroup>
  ```bash cURL theme={null} theme={null}
  curl -N "https://api.crun.ai/api/v1/messages" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -H "anthropic-version: 2023-06-01" \
    -d '{
      "model": "claude-sonnet-4-6",
      "max_tokens": 512,
      "stream": true,
      "messages": [
        {
          "role": "user",
          "content": "Write a three-bullet checklist for API release readiness."
        }
      ]
    }'
  ```

  ```python Python (Anthropic SDK) theme={null} theme={null}
  with client.messages.stream(
      model="claude-sonnet-4-6",
      max_tokens=512,
      messages=[
          {
              "role": "user",
              "content": "Write a three-bullet checklist for API release readiness.",
          }
      ],
  ) as stream:
      for text in stream.text_stream:
          print(text, end="")
  ```

  ```javascript JavaScript (Anthropic SDK) theme={null} theme={null}
  const stream = await client.messages.create({
    model: "claude-sonnet-4-6",
    max_tokens: 512,
    stream: true,
    messages: [
      {
        role: "user",
        content: "Write a three-bullet checklist for API release readiness."
      }
    ]
  });

  for await (const event of stream) {
    if (event.type === "content_block_delta" && event.delta?.text) {
      process.stdout.write(event.delta.text);
    }
  }
  ```
</CodeGroup>

## Response Examples

<CodeGroup>
  ```json basic response theme={null} theme={null}
  {
    "id": "msg_abc123",
    "type": "message",
    "role": "assistant",
    "model": "claude-sonnet-4-6",
    "content": [
      {
        "type": "text",
        "text": "The payments API migration is on track. Authentication updates are complete, integration testing is in progress, and rollback criteria will be finalized before release."
      }
    ],
    "stop_reason": "end_turn",
    "stop_sequence": null,
    "usage": {
      "input_tokens": 18,
      "output_tokens": 34
    }
  }
  ```

  ```text streaming response (SSE) theme={null} theme={null}
  event: message_start
  data: {"type":"message_start","message":{"id":"msg_abc123","type":"message","role":"assistant","model":"claude-sonnet-4-6","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":18,"output_tokens":0}}}

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

  event: content_block_delta
  data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"- Confirm authentication and rate limits."}}

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

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

## Notes

* `max_tokens` is capped by the selected model's output token limit when configured in CRUN.
* `messages` only supports `user` and `assistant` roles. Use the top-level `system` field for system instructions.
* Additional Anthropic-compatible fields are accepted and passed through when supported by the upstream model.
* Tool use, thinking, image blocks, URL sources, and beta features depend on the selected model and upstream provider.
* Unknown model IDs return an OpenAI-style error body with `code: "model_not_found"`.

## Related Resources

<CardGroup cols={3}>
  <Card title="LLM Quickstart" icon="message" href="/models/llm/quickstart">
    Learn the base URL, authentication method, and SDK integration patterns.
  </Card>

  <Card title="OpenAI Responses API" icon="sparkles" href="/models/llm/responses">
    Build OpenAI-compatible workflows with flexible input, structured outputs, and streaming.
  </Card>

  <Card title="Pricing" icon="coins" href="https://crun.ai/pricing">
    Jump to the pricing page to compare billing across different models.
  </Card>
</CardGroup>


## OpenAPI

````yaml models/llm/messages.json post /api/v1/messages
openapi: 3.0.0
info:
  title: CRUN Anthropic-Compatible Messages API
  description: Anthropic-compatible Messages endpoint for CRUN language models.
  version: 1.0.0
  contact:
    name: Technical Support
    email: support@crun.ai
servers:
  - url: https://api.crun.ai
    description: API Server
security:
  - BearerAuth: []
  - ApiKeyAuth: []
paths:
  /api/v1/messages:
    post:
      summary: Create a message
      description: >-
        Anthropic-compatible Messages endpoint.


        - Configure official Anthropic SDKs with `base_url` / `baseURL` set to
        `https://api.crun.ai/api/v1`.

        - Authenticate with your CRUN API key.

        - `anthropic-version` and `anthropic-beta` request headers can be
        forwarded upstream.

        - When `stream=true`, the response is returned as Server-Sent Events
        (`text/event-stream`).
      operationId: models/llm/messages
      parameters:
        - name: anthropic-version
          in: header
          required: false
          schema:
            type: string
            example: '2023-06-01'
          description: Optional Anthropic API version header forwarded upstream.
        - name: anthropic-beta
          in: header
          required: false
          schema:
            type: string
          description: Optional Anthropic beta feature header forwarded upstream.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AnthropicMessagesRequest'
            examples:
              basic:
                summary: Basic message
                value:
                  model: claude-sonnet-4-6
                  max_tokens: 512
                  messages:
                    - role: user
                      content: >-
                        Write a concise project update for a payments API
                        migration.
              system:
                summary: System prompt
                value:
                  model: claude-sonnet-4-6
                  max_tokens: 800
                  system: >-
                    You are a senior API documentation editor. Be concise and
                    precise.
                  messages:
                    - role: user
                      content: >-
                        Rewrite this changelog entry for developers: fixed auth
                        bug.
              conversation:
                summary: Conversation history
                value:
                  model: claude-sonnet-4-6
                  max_tokens: 800
                  messages:
                    - role: user
                      content: >-
                        Give me three names for an internal developer
                        newsletter.
                    - role: assistant
                      content: >-
                        Here are three options: Build Notes, Ship Log, and Dev
                        Dispatch.
                    - role: user
                      content: Make them sound more enterprise-ready.
              vision:
                summary: Vision input
                value:
                  model: claude-sonnet-4-6
                  max_tokens: 800
                  messages:
                    - role: user
                      content:
                        - type: text
                          text: >-
                            Describe this dashboard screenshot and call out any
                            risks.
                        - type: image
                          source:
                            type: base64
                            media_type: image/png
                            data: BASE64_IMAGE_DATA
              tools:
                summary: Tool use
                value:
                  model: claude-sonnet-4-6
                  max_tokens: 1024
                  messages:
                    - role: user
                      content: What is the weather in Paris?
                  tools:
                    - name: get_weather
                      description: Get current weather for a city.
                      input_schema:
                        type: object
                        properties:
                          city:
                            type: string
                        required:
                          - city
                  tool_choice:
                    type: auto
              thinking:
                summary: Thinking
                value:
                  model: claude-sonnet-4-6
                  max_tokens: 2048
                  thinking:
                    type: enabled
                    budget_tokens: 1024
                  messages:
                    - role: user
                      content: >-
                        Compare two API migration plans and recommend the
                        lower-risk option.
              stream:
                summary: Streaming request
                value:
                  model: claude-sonnet-4-6
                  max_tokens: 512
                  stream: true
                  messages:
                    - role: user
                      content: >-
                        Write a three-bullet checklist for API release
                        readiness.
      responses:
        '200':
          description: >-
            Successful response. Returns JSON when `stream=false`, or SSE when
            `stream=true`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicMessageResponse'
              example:
                id: msg_abc123
                type: message
                role: assistant
                model: claude-sonnet-4-6
                content:
                  - type: text
                    text: >-
                      The payments API migration is on track. Authentication
                      updates are complete, integration testing is in progress,
                      and rollback criteria will be finalized before release.
                stop_reason: end_turn
                stop_sequence: null
                usage:
                  input_tokens: 18
                  output_tokens: 34
            text/event-stream:
              schema:
                type: string
                description: >-
                  Server-Sent Events stream. Each event includes an `event:`
                  line and a JSON `data:` line, separated by a blank line.
              example: >+
                event: message_start

                data:
                {"type":"message_start","message":{"id":"msg_abc123","type":"message","role":"assistant","model":"claude-sonnet-4-6","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":18,"output_tokens":0}}}


                event: content_block_start

                data:
                {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}


                event: content_block_delta

                data:
                {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"-
                Confirm authentication and rate limits."}}


                event: message_delta

                data:
                {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"output_tokens":24}}


                event: message_stop

                data: {"type":"message_stop"}

        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/InsufficientCredits'
        '404':
          $ref: '#/components/responses/ModelNotFound'
        '422':
          $ref: '#/components/responses/ValidationError'
        '429':
          $ref: '#/components/responses/RateLimit'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
components:
  schemas:
    AnthropicMessagesRequest:
      type: object
      description: >-
        Anthropic-compatible Messages request. Additional compatible fields are
        accepted and passed through when supported by the upstream model.
      properties:
        model:
          type: string
          minLength: 1
          description: Public model ID returned by `GET /api/v1/models`.
          example: claude-sonnet-4-6
        messages:
          type: array
          minItems: 1
          description: >-
            Conversation messages. Include previous user and assistant turns
            yourself to continue a multi-turn conversation.
          items:
            $ref: '#/components/schemas/AnthropicMessage'
        max_tokens:
          type: integer
          minimum: 1
          description: Maximum output tokens. Capped by the selected model.
          example: 1024
        system:
          description: System prompt. Anthropic Messages uses a top-level `system` field.
          nullable: true
          oneOf:
            - type: string
              example: You are a concise assistant.
            - type: array
              items:
                oneOf:
                  - type: string
                  - type: object
                    additionalProperties: true
        stream:
          type: boolean
          default: false
          description: Whether to return a Server-Sent Events stream.
          example: false
        stop_sequences:
          type: array
          items:
            type: string
          description: List of stop sequences.
          example:
            - END
        temperature:
          type: number
          minimum: 0
          maximum: 1
          description: Sampling temperature.
          example: 0.7
        top_p:
          type: number
          minimum: 0
          maximum: 1
          description: Nucleus sampling value.
          example: 1
        top_k:
          type: integer
          minimum: 0
          description: Top-k sampling value.
          example: 40
        metadata:
          type: object
          description: Developer-defined metadata.
          additionalProperties: true
        tools:
          type: array
          description: >-
            Anthropic tool definitions. Your application executes tool calls and
            returns tool results in a follow-up request.
          items:
            type: object
            additionalProperties: true
        tool_choice:
          description: Tool selection strategy.
          oneOf:
            - type: string
              example: auto
            - type: object
              additionalProperties: true
        thinking:
          type: object
          description: >-
            Extended thinking configuration when supported by the upstream
            model.
          additionalProperties: true
          example:
            type: enabled
            budget_tokens: 1024
      required:
        - model
        - messages
      additionalProperties: true
    AnthropicMessageResponse:
      type: object
      description: Anthropic Messages response.
      additionalProperties: true
      properties:
        id:
          type: string
          example: msg_abc123
        type:
          type: string
          example: message
        role:
          type: string
          example: assistant
        model:
          type: string
          example: claude-sonnet-4-6
        content:
          type: array
          items:
            $ref: '#/components/schemas/ContentBlock'
        stop_reason:
          type: string
          nullable: true
          example: end_turn
        stop_sequence:
          type: string
          nullable: true
        usage:
          type: object
          description: Anthropic usage information.
          additionalProperties: true
          properties:
            input_tokens:
              type: integer
              example: 18
            output_tokens:
              type: integer
              example: 34
            cache_creation_input_tokens:
              type: integer
              example: 0
            cache_read_input_tokens:
              type: integer
              example: 0
    AnthropicMessage:
      type: object
      description: >-
        Anthropic message object. Additional compatible fields are accepted and
        passed through when supported upstream.
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
          description: Message role. Anthropic Messages supports user and assistant.
          example: user
        content:
          description: Message content. Can be a string or an array of content blocks.
          nullable: true
          oneOf:
            - type: string
              example: Write a concise project update.
            - type: array
              items:
                oneOf:
                  - type: string
                  - $ref: '#/components/schemas/ContentBlock'
      required:
        - role
      additionalProperties: true
    ContentBlock:
      type: object
      description: Anthropic content block, such as text, image, tool_use, or tool_result.
      additionalProperties: true
      example:
        type: text
        text: Hello
    OpenAIErrorResponse:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/OpenAIError'
      required:
        - error
    OpenAIError:
      type: object
      properties:
        message:
          type: string
          description: Human-readable error message.
          example: The model `unknown-model` does not exist.
        type:
          type: string
          description: OpenAI-style error type.
          example: invalid_request_error
        param:
          type: string
          nullable: true
          description: Related request parameter, if available.
          example: model
        code:
          type: string
          nullable: true
          description: Machine-readable error code, if available.
          example: model_not_found
      required:
        - message
        - type
  responses:
    BadRequest:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIErrorResponse'
    Unauthorized:
      description: Authentication failed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIErrorResponse'
    InsufficientCredits:
      description: Insufficient credits
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIErrorResponse'
    ModelNotFound:
      description: Unknown model ID
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIErrorResponse'
    ValidationError:
      description: Request validation failed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIErrorResponse'
    RateLimit:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIErrorResponse'
    ServiceUnavailable:
      description: Upstream or internal service failure
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIErrorResponse'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: Use your CRUN API key as a Bearer token for Anthropic-compatible SDKs.
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: Use your CRUN API key in the `X-API-KEY` header.

````