The official Anthropic SDKs talk to the Messages API (/v1/messages). Any server implementing the same request and response shape can sit behind them by changing the base URL and the key; the SDK itself does not need to know it is not talking to Anthropic's own servers.
The base URL is the account root, not the full path
The most common mistake: the Anthropic SDK adds /v1/messages itself, so the base URL should be https://aidiscount.ai, without /v1. Adding /v1 yourself produces a 404 on /v1/v1/messages.
Python
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://aidiscount.ai",
api_key=os.environ["AIDISCOUNT_API_KEY"],
)
resp = client.messages.create(
model="claude-opus-4-8",
max_tokens=1024,
messages=[{"role": "user", "content": "Explain photosynthesis in two sentences."}],
)
print(resp.content[0].text)
The base URL can also be set with the ANTHROPIC_BASE_URL environment variable instead of passing base_url, which is convenient when you don't want to touch existing code that constructs the client without arguments.
TypeScript / JavaScript
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://aidiscount.ai",
apiKey: process.env.AIDISCOUNT_API_KEY,
});
const resp = await client.messages.create({
model: "claude-opus-4-8",
max_tokens: 1024,
messages: [{ role: "user", content: "Explain photosynthesis in two sentences." }],
});
console.log(resp.content[0].text);
Claude Code
Claude Code reads the same two settings from the environment:
export ANTHROPIC_BASE_URL="https://aidiscount.ai"
export ANTHROPIC_AUTH_TOKEN="$AIDISCOUNT_API_KEY"
claude
ANTHROPIC_AUTH_TOKEN sends the key as a bearer token. Claude Code also accepts ANTHROPIC_API_KEY, but it may then ask you to confirm the key on first start. Set only one of the two.
curl, for comparison
curl https://aidiscount.ai/v1/messages \
-H "x-api-key: $AIDISCOUNT_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"model": "claude-opus-4-8", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello"}]}'
Note the header name: x-api-key, not Authorization: Bearer. The SDKs set this header for you from api_key; only build it by hand when calling the API directly.
Streaming and tools
Both work exactly as with Anthropic's own API once the base URL points elsewhere, since the SDK's streaming and tool-use code does not depend on which server is on the other end. See the streaming guide and the tool use guide for the Anthropic-format examples.
Model names
Pass any model ID that supports the Anthropic Messages protocol from the marketplace as the model field; model names are not tied to Anthropic specifically once the base URL has changed.
Common mistakes
- Keeping
/v1in the base URL. Results in a 404 on/v1/v1/messages. - Using
Authorization: Bearerwith a rawfetchcall. The Messages API expectsx-api-key; the SDK handles this, but hand-written requests must set it explicitly. - Omitting
anthropic-version. Required on every direct HTTP request; the official SDKs set it automatically. - Forgetting
max_tokens. The Messages API requires it on every request; there is no default.
Create a free accountRead the API docs