# Anthropic SDK 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](https://docs.privatemind.com/messages-api.html) 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="", 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: "", max_tokens: 1024, messages: [{ role: "user", content: "Hello" }], }); ``` ## Environment variables Both SDKs read their configuration from the environment when you pass nothing: ```bash 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](https://docs.privatemind.com/coding-agents.html#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="", 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](https://docs.privatemind.com/streaming.html#messages-api). ## 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](https://docs.privatemind.com/files.html) | | `messages.batches.*` | Works, on batch-enabled models. See [Message Batches](https://docs.privatemind.com/message-batches.html) | | 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](https://docs.privatemind.com/errors.html#messages-api). ## Where next - [Messages API](https://docs.privatemind.com/messages-api.html) for the full parameter list and the thinking levels. - [Coding agents](https://docs.privatemind.com/coding-agents.html#claude-code) to point Claude Code at PrivateMind. - [OpenAI SDK](https://docs.privatemind.com/openai-sdk.html) if you would rather use the OpenAI shape: same models, same key.