Anthropic SDK
Anthropic’s official SDKs work with OpenPike for Claude models, and for DeepSeek’s Anthropic-compatible endpoint: set the base URL and the key.
Python (anthropic) |
TypeScript (@anthropic-ai/sdk) |
|
|---|---|---|
| Base URL | base_url="https://api.openpike.dev" |
baseURL: "https://api.openpike.dev" |
| Key | api_key= a virtual key |
apiKey: a virtual key |
| Tags on every request | default_headers={"x-openpike-tags": ...} |
defaultHeaders: { "x-openpike-tags": ... } |
The base URL has no /v1: the SDK adds /v1/messages itself. The SDK sends the key in x-api-key, which OpenPike accepts.
Install
Section titled “Install”pip install anthropic # Pythonnpm install @anthropic-ai/sdk # TypeScriptStreaming
Section titled “Streaming”import os
from anthropic import Anthropic
client = Anthropic( base_url="https://api.openpike.dev", api_key=os.environ["OPENPIKE_API_KEY"], default_headers={"x-openpike-tags": "agent=docs-example,env=dev"},)
with client.messages.stream( model="anthropic/claude-haiku-5-5", max_tokens=200, messages=[{"role": "user", "content": "Count from one to five."}],) as stream: for text in stream.text_stream: print(text, end="", flush=True)print()import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ baseURL: "https://api.openpike.dev", apiKey: process.env.OPENPIKE_API_KEY, defaultHeaders: { "x-openpike-tags": "agent=docs-example,env=dev" },});
const stream = client.messages.stream({ model: "anthropic/claude-haiku-5-5", max_tokens: 200, messages: [{ role: "user", content: "Count from one to five." }],});stream.on("text", (text) => process.stdout.write(text));await stream.finalMessage();process.stdout.write("\n");A run ID per task
Section titled “A run ID per task”A run budget caps one agent run’s spend, requests and time. Put the run in the client’s default headers, one client per task:
from anthropic import Anthropic
client = Anthropic( base_url="https://api.openpike.dev", api_key=virtual_key, default_headers={"x-openpike-run": task.id, "x-openpike-run-label": task.title},)const client = new Anthropic({ baseURL: "https://api.openpike.dev", apiKey: virtualKey, defaultHeaders: { "x-openpike-run": task.id, "x-openpike-run-label": task.title },});For one request, pass extra_headers={...} in Python or { headers: {...} } as the second argument in TypeScript.
What works and what does not
Section titled “What works and what does not”- Works:
messages.createandmessages.streamwithanthropic/...models, including tools, prompt caching, extended thinking and beta features, and withdeepseek/...models for the features DeepSeek’s Anthropic-compatible endpoint supports.anthropic-versionandanthropic-betaheaders pass through to the provider. - Does not work: token counting (
messages.count_tokens), the Message Batches API, the Files API and other endpoints besides/v1/messages. - Errors come back in Anthropic’s shape. OpenPike’s own
429blocks use the error typerate_limit_error; a budget block is told apart from Anthropic’s rate limit by its message and by the missingx-openpike-providerheader. See Errors. Retries: keep the SDK’s default retries on429. OpenPike refuses a blocked request before any provider call, so a few retries cost nothing, and they still cover provider5xxerrors. Onbudget_exceeded,loop_detected,scope_pausedorrun_limit_exceeded, stop the task and tell the user instead of retrying the same request.
Example
Section titled “Example”Runnable copies of this setup, with a .env.example, are in the OpenPike examples repo: Python and TypeScript.