# Anthropic Messages SDK — API Store Hub

> VI: Dùng trực tiếp `@anthropic-ai/sdk` hoặc `anthropic` Python với `ANTHROPIC_BASE_URL=https://apistorehub.com` để gọi `/v1/messages`, Extended Thinking, Tool Use và Prompt Caching.
> EN: Use the official Python or TypeScript Anthropic SDK with `ANTHROPIC_BASE_URL=https://apistorehub.com` for native `/v1/messages`, Extended Thinking, tool use, and prompt caching.

- Canonical VI: https://apistorehub.com/vi/tich-hop/anthropic-messages-sdk
- Canonical EN: https://apistorehub.com/en/tich-hop/anthropic-messages-sdk
- Language: Python / TypeScript
- Runtime: anthropic >= 0.40 (Python), @anthropic-ai/sdk >= 0.32 (Node.js)
- Protocol: Anthropic Messages Native (/v1/messages)
- Install: `pip install -U anthropic`
- Auth Env Var: `API_KEY` (prefix `sk-ash-`)

## Step-by-Step Setup
1. Install the official `anthropic` Python package or `@anthropic-ai/sdk` for Node.js.
2. Set `base_url="https://apistorehub.com"` WITHOUT a trailing `/v1` since the SDK appends `/v1/messages`.
3. Authenticate with `x-api-key` or `ANTHROPIC_AUTH_TOKEN` using your `sk-ash-` key.
4. Use `client.messages.stream(...)` and add `cache_control: {"type": "ephemeral"}` on reusable system prompts.

## Production Code Sample
```
import os
import anthropic

client = anthropic.Anthropic(
    base_url="https://apistorehub.com",
    api_key=os.environ["API_KEY"],
)

with client.messages.stream(
    model="claude-sonnet-5-5",
    max_tokens=2048,
    system=[
        {
            "type": "text",
            "text": "You are a senior systems engineer.",
            "cache_control": {"type": "ephemeral"},
        }
    ],
    messages=[{"role": "user", "content": "Review this API retry policy."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
```

## Quick cURL Check
```bash
curl https://apistorehub.com/v1/messages \
  -H "x-api-key: sk-ash-your_key" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-sonnet-5-5","max_tokens":256,"messages":[{"role":"user","content":"Hello Claude"}]}'
```

## Recommended Models (Live ST Pricing)
| Model | Live Price | Context | Datasheet |
|---|---|---|---|
| `claude-sonnet-5-5` | 7,700 ST / 1M tokens | 1M | https://apistorehub.com/llms/models/claude-sonnet-5-5.md |
| `claude-opus-5-5` | 15,300 ST / 1M tokens | 1M | https://apistorehub.com/llms/models/claude-opus-5-5.md |
| `claude-haiku-5-5` | 400 ST / 1M tokens | 200K | https://apistorehub.com/llms/models/claude-haiku-5-5.md |

## FAQ
- **Is `ANTHROPIC_BASE_URL` identical for Claude Code CLI and the Anthropic SDK?**: Yes. Always set it to `https://apistorehub.com` with no trailing `/v1`.
- **Does `/v1/messages` on API Store Hub support base64 Vision blocks?**: Yes. Standard Anthropic image content blocks work natively.
- **How should I handle Anthropic 529 overloaded bursts?**: Use exponential backoff with jitter and fall back to `claude-haiku-5-5` on the same API key.
