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

# Messages

> Accepts Anthropic Messages requests, including video blocks for models that advertise video input. Authenticate with an API key using the Authorization: Bearer header or the x-api-key header.

> [!NOTE]
>
> These examples use the direct API host, `https://api.nano-gpt.com`. It has no IPv6 address, so clients with only IPv6 should use `https://nano-gpt.com` with the same paths. See [API Hosts](https://docs.nano-gpt.com/api-reference/miscellaneous/api-hosts.md).

> [!NOTE]
>
> To set reasoning effort through a custom model ID, append `:reasoning-effort/high` (also `none`, `low`, `medium`, `xhigh`, or `max`). NanoGPT strips the suffix before routing and uses it as the default `output_config.effort` for enabled reasoning levels. `:reasoning-effort/none` instead supplies `thinking: { type: "disabled" }`; `output_config.effort: "none"` is not accepted. Explicit body generation settings, including enabled thinking, take precedence over `none`. The suffix does not bypass model/provider restrictions. See [Reasoning Effort Suffixes](https://docs.nano-gpt.com/api-reference/miscellaneous/model-suffixes.md#reasoning-effort-suffixes).

> [!NOTE]
>
> **API host:** Use `https://api.nano-gpt.com/api` as the base URL for the Anthropic SDK, which appends `/v1/messages`. For raw HTTP requests, use `https://api.nano-gpt.com/api/v1/messages`. See [API Hosts](https://docs.nano-gpt.com/api-reference/miscellaneous/api-hosts.md).

> [!NOTE]
>
> `/v1/messages` accepts **compressed request bodies** (`Content-Encoding: gzip`, `deflate`, or `br`) on authenticated JSON requests — useful for long conversations, where compressed uploads cut time-to-first-token. See [Compressed Request Bodies](https://docs.nano-gpt.com/api-reference/miscellaneous/request-compression.md).

## Overview

The `/v1/messages` endpoint provides full Anthropic API compatibility. Clients using the Anthropic SDK can use NanoGPT by simply changing the base URL -- no code changes required.

NanoGPT accepts requests in the **Anthropic Messages** format, routes them to the requested NanoGPT model, and returns responses back in the Anthropic Messages shape.

For non‑Anthropic models, NanoGPT transparently translates the request to an OpenAI-style chat format internally and then converts the response back to Anthropic Messages format.

> [!NOTE]
>
> Decision models (Jev, Liquid D1, PPLX Decider v1.2, Clef and Clef Flash) use `output_config.format: {"type":"questions","questions":{...}}`, accept only non-streaming user text, and return the answer object as JSON text in `content[0].text`. See [Decisions](https://docs.nano-gpt.com/api-reference/endpoint/decisions.md) for complete examples and limitations.

This endpoint supports:

* Text generation (streaming and non-streaming)
* Multi-turn conversations
* Tool use (function calling)
* Vision (images), video understanding, and document/PDF processing
* Extended thinking (reasoning models)
* Prompt caching
* Token estimates via [`POST /api/v1/messages/count_tokens`](https://docs.nano-gpt.com/api-reference/endpoint/messages-count-tokens)

For asynchronous Claude requests at batch token rates, use [Anthropic Message Batches](https://docs.nano-gpt.com/api-reference/endpoint/batches.md#anthropic-message-batches). The native batch API supports create, list, retrieve, cancel, results, and delete through the official Anthropic SDK. It accepts supported Claude models, with one model per batch and a required `max_tokens` for each request; synchronous Messages model support does not imply batch support.

## Endpoint

```
POST https://api.nano-gpt.com/api/v1/messages
```

## Authentication

Use either header:

* `Authorization: Bearer YOUR_API_KEY`
* `x-api-key: YOUR_API_KEY`

## Request Format

### Required Fields

| Field | Type | Description |
| - | - | - |
| `model` | string | Model identifier (any NanoGPT model, including non‑Anthropic models). Can be left out when `models` is sent. |
| `max_tokens` | number | Maximum tokens to generate (must be a finite number) |
| `messages` | array | Array of conversation messages |

### Optional Fields

| Field | Type | Default | Description |
| - | - | - | - |
| `system` | string or array | -- | System prompt (string or array of text blocks) |
| `stream` | boolean | `false` | Enable streaming responses |
| `models` | string\[] | -- | Models to try in order if one fails before any output is sent. `model` goes first. At most 4 in total. The model that answered is billed, and so is a failed attempt its provider charged for. With two or more different models it needs an API key. See [Model fallbacks](https://docs.nano-gpt.com/api-reference/miscellaneous/provider-selection.md#model-fallbacks). |
| `provider` | string or object | -- | Provider selection controls for this request, applied as on Chat Completions. See [Provider Routing Object](https://docs.nano-gpt.com/api-reference/miscellaneous/provider-selection.md#provider-routing-object). |
| `temperature` | number | -- | Sampling temperature |
| `top_p` | number | -- | Nucleus sampling parameter |
| `top_k` | number | -- | Top-k sampling parameter |
| `stop_sequences` | string\[] | -- | Custom stop sequences |
| `tools` | array | -- | Tool definitions for function calling |
| `tool_choice` | string or object | -- | Control tool selection behavior |
| `disable_parallel_tool_use` | boolean | -- | Disable parallel tool calls |
| `thinking` | object | -- | Enable extended thinking for supported models |
| `metadata` | object | -- | Request metadata (`user` or `user_id`) |
| `service_tier` | string | -- | Service tier: `"auto"`, `"default"`, `"standard"`, `"flex"`, `"fast"`, the legacy `"priority"` alias, or `"batch"` |

### Message Format

Messages must have a `role` (`user` or `assistant`) and `content`:

```json theme={null}
{
  "role": "user",
  "content": "Hello!"
}
```

Or with structured content blocks:

```json theme={null}
{
  "role": "user",
  "content": [
    { "type": "text", "text": "What's in this image?" },
    {
      "type": "image",
      "source": {
        "type": "base64",
        "media_type": "image/jpeg",
        "data": "<base64-encoded-image>"
      }
    }
  ]
}
```

### Content Block Types

#### Text Block

```json theme={null}
{ "type": "text", "text": "Your message here" }
```

#### Image Block (for vision-capable models)

```json theme={null}
{
  "type": "image",
  "source": {
    "type": "base64",
    "media_type": "image/jpeg",
    "data": "<base64-data>"
  }
}
```

Or with URL:

```json theme={null}
{
  "type": "image",
  "source": {
    "type": "url",
    "url": "https://example.com/image.jpg"
  }
}
```

For many or large images, prefer `url` sources over `base64`. See [Image Input](https://docs.nano-gpt.com/api-reference/endpoint/chat-completion.md#image-input) for the 32 MiB request limit on `https://api.nano-gpt.com` (compressed and decompressed) and when to send images inline. `https://nano-gpt.com` has an edge limit of about 4.5 MB per request, compressed or not; use `https://api.nano-gpt.com` for large requests.

Supported media types: `image/jpeg`, `image/png`, `image/gif`, `image/webp`

#### Document Block (for PDF-capable models)

```json theme={null}
{
  "type": "document",
  "source": {
    "type": "base64",
    "media_type": "application/pdf",
    "data": "<base64-data>"
  }
}
```

#### Video Block (for video-capable models)

Use `type: "video"` for new integrations. Inline video bytes use an Anthropic base64 source:

```json theme={null}
{
  "type": "video",
  "source": {
    "type": "base64",
    "media_type": "video/mp4",
    "data": "AAAA..."
  }
}
```

For URL transport, use an HTTPS URL and declare the video MIME type:

```json theme={null}
{
  "type": "video",
  "source": {
    "type": "url",
    "url": "https://cdn.example.com/clip.mp4",
    "media_type": "video/mp4"
  }
}
```

A `document` compatibility block with a `video/*` source is normalized as video. A document with `application/pdf` remains a document. Public remote sources must use HTTPS; inline base64 must be valid. See the [Video Input guide](https://docs.nano-gpt.com/api-reference/miscellaneous/video-input.md) for model discovery, limits, errors, segment behavior, and the equivalent Chat Completions and Responses shapes.

#### Tool Use Block (in assistant messages)

```json theme={null}
{
  "type": "tool_use",
  "id": "tool_abc123",
  "name": "get_weather",
  "input": { "city": "Paris" }
}
```

#### Tool Result Block (in user messages)

```json theme={null}
{
  "type": "tool_result",
  "tool_use_id": "tool_abc123",
  "content": "The weather in Paris is sunny, 22 C"
}
```

### Tool Definitions

```json theme={null}
{
  "tools": [
    {
      "name": "get_weather",
      "description": "Get current weather for a city",
      "input_schema": {
        "type": "object",
        "properties": {
          "city": { "type": "string", "description": "City name" }
        },
        "required": ["city"]
      }
    }
  ]
}
```

### Tool Choice Options

| Value | Description |
| - | - |
| `"auto"` | Model may use tools if appropriate |
| `"none"` | Disable tool use for this request |
| `"any"` | Model must use at least one tool |
| `"required"` | Model must use at least one tool |
| `{"type": "tool", "name": "tool_name"}` | Force use of a specific tool |

### Extended Thinking

For models that support extended thinking (reasoning):

```json theme={null}
{
  "thinking": {
    "type": "enabled",
    "budget_tokens": 8192
  }
}
```

Requirements:

* `budget_tokens` must be >= 1024
* `budget_tokens` must be \< `max_tokens`
* Model must support thinking for the exact model ID you send (check `GET /api/v1/models`)

`:thinking` is model-specific and only works when that exact ID (or a documented alias) exists.
`-thinking` is a legacy alias pattern for some model families only, not universal.
Do not assume `-thinking` works for arbitrary model IDs. Always check `GET /api/v1/models` for exact valid IDs.

If the requested model does not support thinking, NanoGPT automatically ignores/strips the `thinking` parameter and routes the request to the base model.

For Chat Completions compatibility controls, `:reasoning-exclude` (or `reasoning.exclude`) only hides reasoning output; it does not force reasoning compute off. Use `reasoning_effort` / `reasoning.effort` to control reasoning depth, and set `none` to disable reasoning behavior.

## Change Effort Within a Conversation

GPT-6 Astra and Claude Fable 5.1 support [inline reasoning effort updates](https://docs.nano-gpt.com/api-reference/miscellaneous/inline-reasoning-effort.md) using an empty system message: `{"role":"system","content":[],"output_config":{"effort":"high"}}`. Set the baseline with request-level `output_config.effort` and leave it unchanged. A trailing update applies to the generated answer; preserve it before assistant output when replaying history. This Messages form requires the `system` role.

## Response Format

### Non-Streaming Response

```json theme={null}
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "claude-opus-4-5-20251101",
  "content": [
    { "type": "text", "text": "Hello! How can I help you today?" }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 10,
    "output_tokens": 12,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "cache_creation": {
      "ephemeral_5m_input_tokens": 0,
      "ephemeral_1h_input_tokens": 0
    },
    "service_tier": "standard"
  }
}
```

### Stop Reasons

| Stop Reason | Description |
| - | - |
| `end_turn` | Natural end of response |
| `max_tokens` | Hit token limit |
| `stop_sequence` | Hit a custom stop sequence |
| `tool_use` | Model wants to use a tool |
| `content_filter` | Content was filtered |
| `refusal` | The model declined for safety reasons |

If an answer stops with `content_filter` or `refusal` after output has started, the request is charged for its input and the output generated so far. See [Content Policy and Empty Responses](https://docs.nano-gpt.com/api-reference/miscellaneous/error-handling.md#content-policy-and-empty-responses).

### Streaming Response (SSE)

See also: [Streaming Protocol (SSE)](https://docs.nano-gpt.com/api-reference/miscellaneous/streaming-protocol.md).

When `stream: true`, the response is Server-Sent Events with named event types:

#### Event: message\_start

```text theme={null}
event: message_start
data: {"type": "message_start", "message": {"id": "msg_abc", "type": "message", "role": "assistant", "model": "claude-opus-4-5-20251101", "content": [], "stop_reason": null, "usage": {"input_tokens": 10, "output_tokens": 0}}}
```

#### Event: content\_block\_start

```text theme={null}
event: content_block_start
data: {"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}}
```

#### Event: content\_block\_delta

```text theme={null}
event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "Hello"}}
```

#### Event: content\_block\_stop

```text theme={null}
event: content_block_stop
data: {"type": "content_block_stop", "index": 0}
```

#### Event: message\_delta

```text theme={null}
event: message_delta
data: {"type": "message_delta", "delta": {"stop_reason": "end_turn"}, "usage": {"output_tokens": 12}}
```

#### Event: message\_stop

```text theme={null}
event: message_stop
data: {"type": "message_stop"}
```

### Streaming Tool Use

When the model uses tools during streaming:

```text theme={null}
event: content_block_start
data: {"type": "content_block_start", "index": 0, "content_block": {"type": "tool_use", "id": "tool_abc", "name": "get_weather", "input": {}}}

event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "input_json_delta", "partial_json": "{\"city\":"}}

event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "input_json_delta", "partial_json": " \"Paris\"}"}}

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

## Supported Models

### Claude Models (Full Support)

| Model | Streaming | Tools | Vision | Thinking |
| - | - | - | - | - |
| claude-opus-4-6 | Yes | Yes | Yes | Yes\* |
| claude-opus-4-5-20251101 | Yes | Yes | Yes | Yes\* |
| claude-opus-4-1-20250805 | Yes | Yes | Yes | Yes\* |
| claude-sonnet-4-5-20250929 | Yes | Yes | Yes | Yes\* |

\*Use only exact thinking-capable model IDs from `GET /api/v1/models`.

### Other Models (Via Compatibility Layer)

The v1/messages endpoint also works with non-Anthropic models:

| Model | Streaming | Tools | Vision |
| - | - | - | - |
| openai/gpt-6.1-sol | Yes | Yes | Yes |
| google/gemini-3-flash-preview | Yes | Yes | Yes |
| google/gemini-3.1-pro-preview | Yes | Yes | Yes |
| zai-org/glm-4.7 | Yes | Yes | -- |

See the [Models documentation](https://docs.nano-gpt.com/api-reference/endpoint/models.md) for the full list.

## Prompt Caching

For the full guide (supported models, thresholds, pricing, and usage fields), see [Prompt Caching](https://docs.nano-gpt.com/api-reference/miscellaneous/prompt-caching.md).

NanoGPT automatically applies implicit caching on providers/models that support it (including OpenAI, Gemini, and many open-source provider/model routes), with no extra request flags.

Use explicit prompt-caching controls on Claude when you need deterministic cache boundaries, TTL selection, or `stickyProvider` consistency control.

### Enable via Header

```
anthropic-beta: prompt-caching-2024-07-31
```

### TTL Options

* Default: 5-minute cache TTL
* Extended: Add `extended-cache-ttl-2025-04-11` to request 1-hour TTL on Anthropic-native Claude flows

### Cache Control in Content (Explicit Claude Controls)

Add `cache_control` to content blocks for explicit Claude caching:

```json theme={null}
{
  "type": "text",
  "text": "This is a long system prompt...",
  "cache_control": { "type": "ephemeral" }
}
```

### Cache Usage in Response

```json theme={null}
{
  "usage": {
    "input_tokens": 100,
    "output_tokens": 50,
    "cache_creation_input_tokens": 80,
    "cache_read_input_tokens": 0
  }
}
```

## Error Handling

For a general guide across NanoGPT APIs, see [Error Handling](https://docs.nano-gpt.com/api-reference/miscellaneous/error-handling.md).

### Error Response Format

```json theme={null}
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "max_tokens is required",
    "param": "max_tokens"
  }
}
```

### Error Types

| HTTP Status | Error Type | Description |
| - | - | - |
| 400 | `invalid_request_error` | Invalid request (missing fields, bad format) |
| 401 | `authentication_error` | Invalid or missing API key |
| 403 | `permission_error` | Insufficient permissions |
| 404 | `not_found_error` | Unknown model |
| 429 | `rate_limit_error` | Rate limit exceeded |
| 500+ | `api_error` | Server error |

All error responses include an `X-Request-ID` header for support requests.

## Headers

### Request Headers

| Header | Required | Description |
| - | - | - |
| `Authorization` | Yes\* | Bearer token authentication |
| `x-api-key` | Yes\* | Alternative API key header |
| `Content-Type` | Yes | Must be `application/json` |
| `anthropic-beta` | No | Enable beta features (e.g., prompt caching) |
| `anthropic-version` | No | API version (accepted but not required) |

\*One of `Authorization` or `x-api-key` is required.

### BYOK Headers

For Bring Your Own Key:

| Header | Description |
| - | - |
| `x-use-byok` | Set to `true` to use your own API key |
| `x-byok-provider` | Provider name for your key |
| `x-byok-fallback-to-credits` | `true` to continue on credits when your key fails with a retryable error; `false` to never fall back |

The `byok` body field (`{"byok": {"enabled": true, "provider": "openrouter"}}`), your account's Prefer BYOK and a per-API-key default apply too. See [Bring Your Own Key (BYOK)](https://docs.nano-gpt.com/api-reference/miscellaneous/byok.md).

## Examples

### Basic Request (cURL)

```bash theme={null}
curl -X POST https://api.nano-gpt.com/api/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "claude-opus-4-5-20251101",
    "max_tokens": 256,
    "messages": [
      { "role": "user", "content": "Hello!" }
    ]
  }'
```

### Streaming Request (cURL)

```bash theme={null}
curl -N -X POST https://api.nano-gpt.com/api/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "claude-opus-4-5-20251101",
    "stream": true,
    "max_tokens": 256,
    "messages": [{ "role": "user", "content": "Hello!" }]
  }'
```

### With Tools (cURL)

```bash theme={null}
curl -X POST https://api.nano-gpt.com/api/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "claude-opus-4-5-20251101",
    "max_tokens": 1024,
    "tools": [
      {
        "name": "get_weather",
        "description": "Get current weather",
        "input_schema": {
          "type": "object",
          "properties": {
            "city": { "type": "string" }
          },
          "required": ["city"]
        }
      }
    ],
    "messages": [
      { "role": "user", "content": "What is the weather in Tokyo?" }
    ]
  }'
```

### Anthropic SDK (Node.js)

```typescript theme={null}
import Anthropic from "@anthropic-ai/sdk";

const anthropic = new Anthropic({
  apiKey: process.env.NANOGPT_API_KEY,
  baseURL: "https://api.nano-gpt.com/api"
});

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

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

### Anthropic SDK with Streaming (Node.js)

```typescript theme={null}
import Anthropic from "@anthropic-ai/sdk";

const anthropic = new Anthropic({
  apiKey: process.env.NANOGPT_API_KEY,
  baseURL: "https://api.nano-gpt.com/api"
});

const stream = await anthropic.messages.stream({
  model: "claude-opus-4-5-20251101",
  max_tokens: 256,
  messages: [
    { role: "user", content: "Tell me a story" }
  ]
});

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

### Anthropic SDK with Prompt Caching (Node.js)

```typescript theme={null}
import Anthropic from "@anthropic-ai/sdk";

const anthropic = new Anthropic({
  apiKey: process.env.NANOGPT_API_KEY,
  baseURL: "https://api.nano-gpt.com/api"
});

const message = await anthropic.messages.create({
  model: "claude-opus-4-5-20251101",
  max_tokens: 256,
  system: [
    {
      type: "text",
      text: "You are a helpful assistant with expertise in...",
      cache_control: { type: "ephemeral" }
    }
  ],
  messages: [
    { role: "user", content: "Hello!" }
  ]
}, {
  headers: {
    "anthropic-beta": "prompt-caching-2024-07-31"
  }
});
```

### Vision Example (Node.js)

```typescript theme={null}
import Anthropic from "@anthropic-ai/sdk";
import fs from "fs";


const anthropic = new Anthropic({
  apiKey: process.env.NANOGPT_API_KEY,
  baseURL: "https://api.nano-gpt.com/api"
});

const imageData = fs.readFileSync("image.jpg").toString("base64");

const message = await anthropic.messages.create({
  model: "claude-opus-4-5-20251101",
  max_tokens: 1024,
  messages: [
    {
      role: "user",
      content: [
        { type: "text", text: "What's in this image?" },
        {
          type: "image",
          source: {
            type: "base64",
            media_type: "image/jpeg",
            data: imageData
          }
        }
      ]
    }
  ]
});
```

### Python SDK

```python theme={null}
import anthropic

client = anthropic.Anthropic(
    api_key="YOUR_NANOGPT_API_KEY",
    base_url="https://api.nano-gpt.com/api"
)

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

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

## Limits

| Limit | Value |
| - | - |
| Request timeout | 800 seconds |
| Tool argument size | \~100 KB per tool call |
| Tool definitions | Up to 1,024 tools and 1 MiB of tool JSON per request |
| Image types | JPEG, PNG, GIF, WebP |

## Limitations

* GPU-TEE models do not support streaming through `POST /api/v1/messages`. Use `POST /api/v1/chat/completions` if you need streaming with GPU-TEE models.

## Migration from Anthropic

To migrate from Anthropic's API to NanoGPT:

1. Change the base URL:

   * From: `https://api.anthropic.com`
   * To: `https://api.nano-gpt.com/api`

   The full endpoint will be: `https://api.nano-gpt.com/api/v1/messages`

2. Use your NanoGPT API key instead of your Anthropic key

3. No other code changes required -- the API is fully compatible

## Service tier compatibility

Anthropic-style service tiers are normalized when routing to providers that support service tiers:

* `standard` → `default`
* `default` → `default`
* `flex` → `flex`
* `fast` → higher-priority processing where supported
* `priority` → legacy alias for `fast` on OpenAI models; compatible non-OpenAI providers may continue to use the Priority name
* `batch` → ignored for service-tier routing

Before sending a tiered request, call [`GET /api/v1/models?detailed=true`](https://docs.nano-gpt.com/api-reference/endpoint/models) and inspect the selected model's `supported_service_tiers` array. The basic model list intentionally omits this field for OpenAI compatibility. An empty array means the model supports only the default tier.

Flex and Fast/Priority availability is model- and provider-specific. If you explicitly force a provider that does not support service tiers, the requested tier may be ignored by the upstream provider, or routing and pricing may differ from the default route.

## Notes

* The `anthropic-version` header is accepted but not required
* Token usage numbers use NanoGPT's token accounting (may differ slightly from Anthropic's exact counts)
* All Anthropic SDK features are supported, including streaming, tools, and caching


## OpenAPI

````yaml POST /v1/messages
openapi: 3.1.0
info:
  title: NanoGPT API
  description: >-
    API documentation for the NanoGPT language, image, video, speech-to-text,
    and text-to-speech generation services
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.nano-gpt.com/api
    description: Direct API host
  - url: https://nano-gpt.com/api
    description: Website host, for IPv6-only clients and the routes that name it
security: []
paths:
  /v1/messages:
    post:
      tags:
        - Anthropic
      summary: Create an Anthropic-compatible message
      description: >-
        Accepts Anthropic Messages requests, including video blocks for models
        that advertise video input. Authenticate with an API key using the
        Authorization: Bearer header or the x-api-key header.
      operationId: createMessage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AnthropicMessageRequest'
      responses:
        '200':
          description: Anthropic message response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicMessage'
            text/event-stream:
              schema:
                type: string
        '400':
          description: >-
            Bad Request. Video errors include video_input_not_supported,
            invalid_video_url_scheme, invalid_video_data_url,
            invalid_video_base64, invalid_video_mime_type, missing_video_source,
            video_file_id_not_supported, invalid_video_segment,
            video_segment_not_supported, and youtube_video_route_not_supported.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
      security:
        - bearerAuth: []
        - apiKeyAuth: []
components:
  schemas:
    AnthropicMessageRequest:
      type: object
      required:
        - messages
      properties:
        output_config:
          $ref: '#/components/schemas/InlineReasoningEffort'
          description: >-
            Request-level effort baseline. Keep unchanged when using inline
            output_config updates.
        model:
          type: string
          description: >-
            Model ID or compatibility alias. Required unless models is sent.
            Append :reasoning-effort/<effort>, where effort is none, low,
            medium, high, xhigh, or max, to supply a default
            output_config.effort for enabled reasoning levels; none instead
            supplies thinking: { type: "disabled" }. The suffix is stripped
            before model routing and is not listed as a separate model. Explicit
            reasoning generation settings take precedence, including enabled
            thinking when the suffix is none. The none suffix requests disabled
            reasoning where supported; it does not bypass model/provider
            restrictions. Other effort levels remain model/provider-specific.
        models:
          type: array
          description: >-
            Models to try in order if one fails before any output is sent. model
            goes first, and models can also be sent alone. At most 4 models per
            request. With two or more different models it needs an API key. The
            model that answered is billed, and so is a failed attempt its
            provider charged for.
          maxItems: 4
          items:
            type: string
        provider:
          description: >-
            Provider selection controls for this request, applied as on Chat
            Completions.
          oneOf:
            - type: string
              description: Provider ID or accepted provider display name/alias.
            - $ref: '#/components/schemas/ProviderRoutingObject'
        max_tokens:
          type: integer
        messages:
          type: array
          items:
            type: object
            required:
              - role
            properties:
              role:
                type: string
                enum:
                  - user
                  - assistant
                  - system
              content:
                oneOf:
                  - type: string
                  - type: array
                    items:
                      anyOf:
                        - $ref: '#/components/schemas/AnthropicVideoBlock'
                        - type: object
                          additionalProperties: true
                  - type: 'null'
              output_config:
                $ref: '#/components/schemas/InlineReasoningEffort'
                description: >-
                  Astra/Fable 5.1 inline effort update. Requires system role and
                  empty content; trailing updates apply to the generated
                  response.
            additionalProperties: true
            allOf:
              - if:
                  required:
                    - output_config
                then:
                  properties:
                    role:
                      const: system
                    content:
                      enum:
                        - ''
                        - []
                        - null
                else:
                  required:
                    - content
                  properties:
                    role:
                      enum:
                        - user
                        - assistant
                    content:
                      not:
                        type: 'null'
      additionalProperties: true
    AnthropicMessage:
      type: object
      properties:
        id:
          type: string
        type:
          type: string
        role:
          type: string
        model:
          type: string
        content:
          type: array
          items:
            type: object
            additionalProperties: true
        stop_reason:
          type:
            - string
            - 'null'
        usage:
          type: object
          additionalProperties: true
      additionalProperties: true
    Error:
      required:
        - error
        - message
      type: object
      properties:
        error:
          type: integer
          format: int32
        message:
          type: string
    InlineReasoningEffort:
      type: object
      required:
        - effort
      properties:
        effort:
          type: string
          enum:
            - minimal
            - low
            - medium
            - high
            - xhigh
            - max
          description: >-
            Astra: low, medium, high, xhigh. Fable 5.1: low, medium, high,
            xhigh, max; minimal maps to low. Other models and none are
            unsupported for inline updates.
      additionalProperties: false
    ProviderRoutingObject:
      type: object
      description: >-
        Structured per-request provider routing controls. Per-request controls
        take precedence over saved provider preferences and are not merged with
        them.
      properties:
        order:
          type: array
          description: >-
            Soft provider preference order. NanoGPT tries these providers first
            when possible, but this does not hard-pin routing to only these
            providers. Unknown providers are ignored.
          items:
            type: string
        only:
          type: array
          description: >-
            Hard provider pin. NanoGPT restricts routing to these providers and
            fails instead of silently routing elsewhere. Unknown providers
            return a structured 400 error with code provider_unknown_provider.
          items:
            type: string
        ignore:
          type: array
          description: Providers to exclude from routing. Unknown providers are ignored.
          items:
            type: string
        sort:
          description: >-
            Routing preference. speed, throughput, latency, and price actively
            request that strategy. auto, none, and default are accepted to
            suppress stored/default routing preferences without requesting a
            provider sort. The object form is {"by": "price", "partition":
            "model"}.
          oneOf:
            - type: string
              enum:
                - speed
                - throughput
                - latency
                - price
                - auto
                - none
                - default
            - type: object
              required:
                - by
              properties:
                by:
                  type: string
                  enum:
                    - speed
                    - throughput
                    - latency
                    - price
                    - auto
                    - none
                    - default
                partition:
                  type: string
                  description: >-
                    model (the default) keeps models in the order sent. none
                    isn't supported with two or more different models and
                    returns 400 provider_sort_partition_not_supported.
                  enum:
                    - model
                    - none
        quantizations:
          type: array
          description: >-
            Hard allowlist of model weight quantization levels. Providers
            without matching known quantization metadata are excluded unless
            unknown is included explicitly.
          minItems: 1
          items:
            type: string
            enum:
              - int4
              - fp4
              - fp6
              - int8
              - fp8
              - fp16
              - bf16
              - fp32
              - unknown
        min_quantization:
          type: string
          description: >-
            Minimum model weight quantization precision floor. Quantizations are
            ordered by bit width; integer and floating-point formats with the
            same bit width are treated as equivalent. unknown is not valid
            because it cannot be compared to a precision floor.
          enum:
            - int4
            - fp4
            - fp6
            - int8
            - fp8
            - fp16
            - bf16
            - fp32
        max_price:
          type: object
          description: >-
            Optional provider price caps in USD per 1 million tokens. Pricing
            checks are best-effort when provider pricing is unknown.
          properties:
            prompt:
              type: number
              description: Maximum prompt/input price in USD per 1 million tokens.
              minimum: 0
            completion:
              type: number
              description: Maximum completion/output price in USD per 1 million tokens.
              minimum: 0
        preferred_max_latency:
          description: >-
            Preferred maximum time to first token, in seconds. A number applies
            to p50. An object sets any of p50, p75, p90 or p99. Providers that
            miss a cutoff move to the end of the ranking and are never excluded.
            Cutoffs need provider.sort, or a provider.max_price that implies
            price routing, to act; sent alone they do nothing.
          oneOf:
            - type: number
              minimum: 0
            - type: object
              additionalProperties: false
              properties:
                p50:
                  type: number
                  minimum: 0
                p75:
                  type: number
                  minimum: 0
                p90:
                  type: number
                  minimum: 0
                p99:
                  type: number
                  minimum: 0
        preferred_min_throughput:
          description: >-
            Preferred minimum output speed, in tokens per second. A number
            applies to p50. An object sets any of p50, p75, p90 or p99.
            Providers that miss a cutoff move to the end of the ranking and are
            never excluded. Cutoffs need provider.sort, or a provider.max_price
            that implies price routing, to act; sent alone they do nothing.
          oneOf:
            - type: number
              minimum: 0
            - type: object
              additionalProperties: false
              properties:
                p50:
                  type: number
                  minimum: 0
                p75:
                  type: number
                  minimum: 0
                p90:
                  type: number
                  minimum: 0
                p99:
                  type: number
                  minimum: 0
        allow_fallbacks:
          type: boolean
          description: >-
            When false, disables cross-provider fallback for this request. On a
            native /v1/responses route it skips some alternative attempts, not
            all of them.
        require_parameters:
          type: boolean
          description: >-
            When true, requires the selected provider to support the requested
            parameters on routes that support parameter-level capability checks.
    AnthropicVideoBlock:
      type: object
      required:
        - type
        - source
      properties:
        type:
          const: video
        source:
          oneOf:
            - $ref: '#/components/schemas/AnthropicVideoSourceBase64'
            - $ref: '#/components/schemas/AnthropicVideoSourceUrl'
      additionalProperties: true
    AnthropicVideoSourceBase64:
      type: object
      required:
        - type
        - media_type
        - data
      properties:
        type:
          const: base64
        media_type:
          type: string
          pattern: ^video/
        data:
          type: string
          contentEncoding: base64
      additionalProperties: false
    AnthropicVideoSourceUrl:
      type: object
      required:
        - type
        - url
        - media_type
      properties:
        type:
          const: url
        url:
          type: string
          format: uri
          pattern: ^https://
        media_type:
          type: string
          pattern: ^video/
      additionalProperties: false
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.