Skip to Content
GuidesClaude / Anthropic SDK Integration

Claude / Anthropic SDK Integration

Route Anthropic Claude API calls through the Curate-Me gateway for cost tracking, rate limiting, PII scanning, and governance. The gateway exposes a native Anthropic Messages endpoint — no translation layer needed.

Prerequisites

# Python pip install anthropic # TypeScript npm install @anthropic-ai/sdk

Python Setup

Point the Anthropic SDK at the gateway’s /v1 endpoint:

import anthropic client = anthropic.Anthropic( api_key="sk-ant-your-key", base_url="https://api.curate-me.ai/v1", default_headers={ "X-CM-API-Key": "cm_sk_xxx", "X-Provider-Key": "sk-ant-your-key", "X-CM-Tags": "project=my-app,env=production", }, )

The gateway speaks the Anthropic Messages API natively. No SDK changes beyond the base_url and headers.

Non-Streaming

message = client.messages.create( model="claude-sonnet-4-20250514", max_tokens=200, messages=[ {"role": "user", "content": "Explain what an AI gateway proxy does in two sentences."} ], ) print(message.content[0].text) print(f"Tokens: input={message.usage.input_tokens}, output={message.usage.output_tokens}")

Streaming

with client.messages.stream( model="claude-sonnet-4-20250514", max_tokens=300, messages=[ {"role": "user", "content": "What are three benefits of LLM cost governance?"} ], ) as stream: for text in stream.text_stream: print(text, end="", flush=True)

SSE streaming works transparently — the gateway passes through events from Anthropic without buffering.

System Prompts

response = client.messages.create( model="claude-sonnet-4-20250514", max_tokens=200, system="You are a concise technical advisor. Reply in one paragraph.", messages=[ {"role": "user", "content": "How does PII scanning protect AI applications?"} ], )

TypeScript Setup

import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic({ apiKey: "sk-ant-your-key", baseURL: "https://api.curate-me.ai/v1", defaultHeaders: { "X-CM-API-Key": "cm_sk_xxx", "X-Provider-Key": "sk-ant-your-key", "X-CM-Tags": "project=my-app,env=production", }, }); const message = await client.messages.create({ model: "claude-sonnet-4-20250514", max_tokens: 200, messages: [{ role: "user", content: "Hello!" }], });

Extended Thinking

Claude models with extended thinking work through the gateway. The gateway’s reasoning token cap (governance step 1.7) applies:

response = client.messages.create( model="claude-sonnet-4-20250514", max_tokens=16384, thinking={ "type": "enabled", "budget_tokens": 10000, }, messages=[ {"role": "user", "content": "Solve this step by step: ..."} ], )

Reasoning token limits per tier: Free 4,096 | Starter 16,384 | Growth 65,536 | Enterprise unlimited.

Authentication Options

The gateway accepts provider keys in two ways:

# Option 1: Explicit header (preferred) client = anthropic.Anthropic( base_url="https://api.curate-me.ai/v1", api_key="sk-ant-your-key", default_headers={ "X-CM-API-Key": "cm_sk_xxx", "X-Provider-Key": "sk-ant-your-key", }, ) # Option 2: Stored secrets (no provider key per-request) # Configure your Anthropic key in the dashboard, then: client = anthropic.Anthropic( base_url="https://api.curate-me.ai/v1", api_key="cm_sk_xxx", # Gateway key acts as both auth and routing )

Environment Variables

CM_GATEWAY_URL=https://api.curate-me.ai CM_API_KEY=cm_sk_xxx PROVIDER_KEY=sk-ant-your-anthropic-key
import os client = anthropic.Anthropic( api_key=os.environ["PROVIDER_KEY"], base_url=f"{os.environ['CM_GATEWAY_URL']}/v1", default_headers={ "X-CM-API-Key": os.environ["CM_API_KEY"], "X-Provider-Key": os.environ["PROVIDER_KEY"], }, )

Next Steps