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

# Native Anthropic streaming

> Stream native Anthropic Messages events through the Planck AI Gateway.

Use the native Anthropic route when your application depends on Anthropic's request shape, SDK helpers, or named SSE events. The native base path is:

```text theme={null}
https://api.inquantum.ai/anthropic/v1/*
```

Native passthrough uses two credentials:

* `Planck-Auth` authenticates the request to Planck.
* `x-api-key` authenticates the request to Anthropic.

<Note>
  For provider-independent routing with an Anthropic-style request, use the
  mapped [`POST /v1/messages`](/rest/ai-gateway/post-v1-messages) route instead.
</Note>

## Stream with the Anthropic SDK

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

  const client = new Anthropic({
    apiKey: process.env.ANTHROPIC_API_KEY,
    baseURL: "https://api.inquantum.ai/anthropic",
    defaultHeaders: {
      "Planck-Auth": `Bearer ${process.env.PLANCK_API_KEY}`,
    },
  });

  const stream = client.messages
    .stream({
      model: "claude-4.5-sonnet",
      max_tokens: 512,
      messages: [{ role: "user", content: "Explain vector search simply." }],
    })
    .on("text", (text) => process.stdout.write(text));

  const message = await stream.finalMessage();
  console.log(`\n${message.usage.output_tokens} output tokens`);
  ```

  ```python Python theme={null}
  import os
  from anthropic import Anthropic

  client = Anthropic(
      api_key=os.environ["ANTHROPIC_API_KEY"],
      base_url="https://api.inquantum.ai/anthropic",
      default_headers={
          "Planck-Auth": f"Bearer {os.environ['PLANCK_API_KEY']}"
      },
  )

  with client.messages.stream(
      model="claude-4.5-sonnet",
      max_tokens=512,
      messages=[{"role": "user", "content": "Explain vector search simply."}],
  ) as stream:
      for text in stream.text_stream:
          print(text, end="", flush=True)

      message = stream.get_final_message()
      print(f"\n{message.usage.output_tokens} output tokens")
  ```

  ```bash cURL theme={null}
  curl -N https://api.inquantum.ai/anthropic/v1/messages \
    -H "Planck-Auth: Bearer $PLANCK_API_KEY" \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "claude-4.5-sonnet",
      "max_tokens": 512,
      "messages": [
        {"role": "user", "content": "Explain vector search simply."}
      ],
      "stream": true
    }'
  ```
</CodeGroup>

## Event lifecycle

Native Anthropic streams use named SSE events rather than OpenAI `chat.completion.chunk` objects.

1. `message_start` opens the message and includes initial usage.
2. `content_block_start` opens a text, thinking, or tool-use block.
3. One or more `content_block_delta` events add content to that block.
4. `content_block_stop` closes the block.
5. `message_delta` updates message-level fields such as the stop reason and cumulative usage.
6. `message_stop` closes the message.

`ping` events can appear anywhere between those events.

```text Native SSE response theme={null}
event: message_start
data: {"type":"message_start","message":{"id":"msg_123","type":"message","role":"assistant","content":[],"model":"claude-4.5-sonnet","stop_reason":null,"usage":{"input_tokens":14,"output_tokens":1}}}

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

event: ping
data: {"type":"ping"}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Vector search"}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" finds items with similar meaning."}}

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

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

event: message_stop
data: {"type":"message_stop"}
```

## Text, thinking, and tool deltas

Inspect the delta `type` instead of assuming every content event contains text.

| Delta type         | Field to accumulate  | When to process                                     |
| ------------------ | -------------------- | --------------------------------------------------- |
| `text_delta`       | `delta.text`         | Render immediately.                                 |
| `thinking_delta`   | `delta.thinking`     | Preserve only when requested and allowed.           |
| `signature_delta`  | `delta.signature`    | Preserve with its thinking block.                   |
| `input_json_delta` | `delta.partial_json` | Concatenate, then parse after `content_block_stop`. |

Tool arguments in `input_json_delta` are partial JSON strings. They follow the same rule as streamed OpenAI tool calls: accumulate first, parse once the block is complete.

## Errors and forward compatibility

An error can arrive after the HTTP stream has started:

```text Error event theme={null}
event: error
data: {"type":"error","error":{"type":"overloaded_error","message":"Overloaded"}}
```

Handle `error` events even when the HTTP response began with `200`. Ignore unknown event types safely; Anthropic can add event types over time without changing the API version.

## Choose the right route

| Requirement                                  | Recommended route                                        |
| -------------------------------------------- | -------------------------------------------------------- |
| OpenAI SDK or provider-independent routing   | [`POST /v1/chat/completions`](/gateway/streaming)        |
| Anthropic-style request with gateway mapping | [`POST /v1/messages`](/rest/ai-gateway/post-v1-messages) |
| Anthropic SDK and native event semantics     | `/anthropic/v1/messages`                                 |
| Other native Anthropic endpoints             | `/anthropic/v1/*`                                        |

<CardGroup cols={2}>
  <Card title="Native Anthropic reference" icon="brackets-curly" href="/rest/ai-gateway/anthropic-native">
    Review authentication and native path behavior.
  </Card>

  <Card title="OpenAI-compatible streaming" icon="messages-square" href="/gateway/streaming">
    Stream across supported providers with Chat Completions.
  </Card>
</CardGroup>
