Get API key

Anthropic SDK

View as Markdown

Use the official Anthropic Python or TypeScript client. Set the base URL and api_key.

Point the official Anthropic clients at PrivateMind by setting a custom base URL and key. The rest of your code stays the same, and the calls go to the Messages API on your org's models.

Python

Python
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.privatemind.com",
    api_key="PMIND...:abcdef...",
)

message = client.messages.create(
    model="<model-id>",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(next(b.text for b in message.content if b.type == "text"))

anthropic.AsyncAnthropic takes the same two arguments.

TypeScript / Node.js

TypeScript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "https://api.privatemind.com",
  apiKey: "PMIND...:abcdef...",
});

const message = await client.messages.create({
  model: "<model-id>",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello" }],
});

Environment variables

Both SDKs read their configuration from the environment when you pass nothing:

cURL
export ANTHROPIC_BASE_URL=https://api.privatemind.com
export ANTHROPIC_API_KEY="PMIND...:abcdef..."

You can set ANTHROPIC_AUTH_TOKEN in place of ANTHROPIC_API_KEY. It sends the key as Authorization: Bearer, not x-api-key, and PrivateMind accepts both. Tools built on the SDKs, Claude Code among them, read the same variables.

Note

Leave /v1 off the base URL. The SDKs add it, so https://api.privatemind.com/v1 would request /v1/v1/messages and return 404.

Streaming

Python
with client.messages.stream(
    model="<model-id>",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a haiku about TCP."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
    final = stream.get_final_message()

The event stream follows the Messages API protocol exactly. See Streaming.

What works, what doesn't

SDK surface Status
messages.create, messages.stream, messages.count_tokens Works
Tool use, including parallel calls and tool_result errors Works
Thinking, output_config.effort, structured output, stop sequences, prefill Works
Images and text documents, inline or as a file source Works; PDFs return 400
models.list, models.retrieve Works; lists your catalog's chat models
files.* Works, on the same store as the OpenAI Files API
messages.batches.* Works, on batch-enabled models. See Message Batches
Server tools (web_search, web_fetch, code_execution, MCP connector) Not run; the model answers without them
Admin, workspace and skills APIs Not exposed; 404

Errors raise the SDK's usual typed exceptions (AuthenticationError, RateLimitError, OverloadedError and so on). The SDK's built-in retries handle 429 and 529 correctly. See Errors.

Where next

  • Messages API for the full parameter list and the thinking levels.
  • Coding agents to point Claude Code at PrivateMind.
  • OpenAI SDK if you would rather use the OpenAI shape: same models, same key.