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

# Anthropic SDK & Claude Agent SDK

> Use the Anthropic Python SDK and the Claude Agent SDK against Valar's /v1/messages surface, and pick a completion window with a header

Valar's `POST /v1/messages` endpoint speaks the Anthropic Messages API, so the official Anthropic Python SDK and the Claude Agent SDK work against Valar with a base URL and key change. The same [models](/models) and [completion windows](/inference-modes#completion-windows) work as on the Responses and Chat Completions surfaces; see the [API support matrix](/support) for the full feature list.

## Anthropic Python SDK

```bash theme={"system"}
pip install anthropic
```

Point the SDK at Valar. Use `auth_token` (sends `Authorization: Bearer`) — or `api_key` (sends `x-api-key`); Valar accepts both.

```python theme={"system"}
from anthropic import Anthropic

client = Anthropic(
    auth_token="YOUR_VALAR_API_KEY",
    base_url="https://api.valarhq.ai",  # no /v1 — the SDK appends it
)

message = client.messages.create(
    model="zai-org/GLM-5.2",
    max_tokens=2048,
    messages=[{"role": "user", "content": "Explain transformers in one sentence."}],
)

# Models may emit thinking blocks before the text response — extract the text block.
text = next(block.text for block in message.content if block.type == "text")
print(text)
print(message.stop_reason, message.usage.input_tokens, message.usage.output_tokens)
```

The full Anthropic surface is supported — `system` prompts, `tools`, `thinking`, `stop_sequences`, `top_k`, `stream: true`, and [structured outputs](/structured-outputs) via `output_config.format`. System prompts go in the top-level `system` field, not as a `role: "system"` message. Reasoning-capable models emit `thinking` blocks by default; control the depth with `thinking` or `output_config.effort` (`low` / `medium` / `high` / `xhigh` / `max`). Use `max_tokens` generously (thinking counts toward the output budget) and iterate `content` for the `text` block rather than indexing `content[0]`.

### Streaming

```python theme={"system"}
with client.messages.stream(
    model="zai-org/GLM-5.2",
    max_tokens=2048,
    messages=[{"role": "user", "content": "Explain transformers."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
    final = stream.get_final_message()
```

### Choose a completion window

Set the window either in the request body or through a header. The body field takes precedence when both are set.

```python theme={"system"}
# Body — the natural path for the Anthropic SDK
message = client.messages.create(
    model="zai-org/GLM-5.2",
    max_tokens=2048,
    messages=[{"role": "user", "content": "hi"}],
    metadata={"completion_window": "standard"},
)
```

```python theme={"system"}
# Header — set once on the client, or per request with extra_headers
client = Anthropic(
    auth_token="YOUR_VALAR_API_KEY",
    base_url="https://api.valarhq.ai",
    default_headers={"X-Valar-Completion-Window": "standard"},
)
```

Accepted values are `"asap"` (Now), `"priority"`, `"standard"`, and `"flex"`. See [Inference modes](/inference-modes#completion-windows).

<Note>
  `"flex"` targets a \~5-minute turn time and is designed for background use. The Messages API has no `background` parameter, so a synchronous flex call blocks for up to 5 minutes and may 504 at the gateway's wait ceiling. For flex work, use the [Responses API](/inference-modes#completion-windows) with `background=true`, which returns a queued response you poll for later.
</Note>

## Claude Agent SDK

The Claude Agent SDK runs the Claude Code agent loop as a library. Because the SDK owns the request body, set the completion window through the `X-Valar-Completion-Window` header via `ANTHROPIC_CUSTOM_HEADERS` rather than body metadata.

```bash theme={"system"}
pip install claude-agent-sdk
```

```python theme={"system"}
import asyncio
from claude_agent_sdk import ClaudeAgentOptions, query

async def main():
    options = ClaudeAgentOptions(
        model="zai-org/GLM-5.2",
        max_turns=5,
        allowed_tools=[],
        env={
            "ANTHROPIC_BASE_URL": "https://api.valarhq.ai",
            "ANTHROPIC_API_KEY": "YOUR_VALAR_API_KEY",
            "ANTHROPIC_CUSTOM_HEADERS": "X-Valar-Completion-Window: standard",
        },
    )

    async for message in query(prompt="Summarize what this repo does in two sentences.", options=options):
        for block in getattr(message, "content", []) or []:
            if getattr(block, "text", None):
                print(block.text, end="")

asyncio.run(main())
```

`ANTHROPIC_API_KEY` sends `x-api-key`, which Valar accepts. `allowed_tools` enables the SDK's built-in tools (`Read`, `Grep`, `Bash`, …) or your own MCP servers — leave it empty for a plain completion.

## Next steps

<CardGroup cols={2}>
  <Card title="Inference modes" href="/inference-modes">
    Realtime, async, and completion windows.
  </Card>

  <Card title="API support matrix" href="/support">
    What /v1/messages accepts and returns.
  </Card>
</CardGroup>
