# Anthropic SDK (/en/docs/cookbook/sdk/anthropic-sdk)









Connect Praxis through the official Anthropic SDK—keep every line of your existing Anthropic code, change one `baseURL`. This page is verified against both Node and Python (other languages share the shape).

Every step lists its **expected result**: follow along yourself, or hand this page to an AI assistant that can operate your computer and let it do the install, run, and verification for you.

## What you'll accomplish [#what-youll-accomplish]

* Call Praxis models with the Anthropic SDK and get replies plus usage
* Done when: `hello.mjs` prints a reply with `usage`, and `stream.mjs` prints token by token
* Time needed: **3 minutes** (excluding the Node.js install)
* Protocol: Anthropic-compatible (`/anthropic`)

## Prerequisites [#prerequisites]

Confirm each item before you start:

* **A Praxis API key** (starting with `sk-praxis-`). If you don't have one, create it at [Console → API Keys](https://console.deepraxis.ai/keys&#x29;: click "Create Key"—the name is required, validity defaults to 90 days (or pick permanent); the success dialog shows the full key with a "Copy Key" button, and after it closes the list shows only a masked value—re-copy the full key any time from the copy icon on its row. New accounts ship with **$1 of free credit**. See [Quickstart](/en/docs/developers/model/quickstart) for the full flow.
* **Node.js 18 or newer** (check `node --version`; [Bun](https://bun.sh) works too).
* **Install the SDK**—note the package name is `@anthropic-ai/sdk` (the bare `anthropic` on npm is an unrelated placeholder):

  ```bash
  npm install @anthropic-ai/sdk
  ```

  Expected: the install succeeds.

## First request [#first-request]

Put the key in an environment variable first (`export PRAXIS_API_KEY=sk-praxis-…`; PowerShell: `$env:PRAXIS_API_KEY="…"`), then create `hello.mjs`:

```javascript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "https://api.deepraxis.com/anthropic",
  apiKey: "sk-praxis-your-key",
});

const message = await client.messages.create({
  model: "deepseek-flash",
  max_tokens: 256,
  messages: [{ role: "user", content: "Introduce yourself in one sentence" }],
});

console.log(message.content.find((b) => b.type === "text")?.text);
console.log(message.usage);
```

Run it:

```bash
node hello.mjs
```

Expected: a reply prints, followed by `usage`—at least `input_tokens` / `output_tokens&#x60;; the SDK adds caching and service-tier fields on top. Two notes: **`max_tokens` is required** (an Anthropic-protocol rule); `content` is an array of blocks—the one with `type` `text` is the reply, possibly after a `thinking` block on reasoning models.

<img alt="The real output of the sample script in a terminal" src="__img0" />

## Python version [#python-version]

```bash
pip install anthropic
```

Create `hello.py`:

```python
import os
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.deepraxis.com/anthropic",
    api_key=os.environ["PRAXIS_API_KEY"],
)

message = client.messages.create(
    model="deepseek-flash",
    max_tokens=256,
    messages=[{"role": "user", "content": "Introduce yourself in one sentence"}],
)

print(next(b.text for b in message.content if b.type == "text"))
print(message.usage)
```

Run `python3 hello.py`. Expected: a reply prints, followed by `Usage`—`max_tokens` is likewise required, and `content` is an array of blocks. Streaming uses the `client.messages.stream(...)` context manager, mirroring Node.

<img alt="The real output of the Python sample" src="__img1" />

## Streaming [#streaming]

Create `stream.mjs`:

```javascript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "https://api.deepraxis.com/anthropic",
  apiKey: process.env.PRAXIS_API_KEY,
});

const stream = client.messages.stream({
  model: "deepseek-flash",
  max_tokens: 256,
  messages: [{ role: "user", content: "Explain what an API is in two sentences" }],
});

for await (const event of stream) {
  if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
    process.stdout.write(event.delta.text);
  }
}
console.log();
```

Expected: the reply prints token by token, ending with a newline. Streaming support varies per model route; a route that isn't enabled yet reports `STREAMING_UNPROVEN`—drop streaming or switch models and retry.

<img alt="The streaming sample in a terminal: the reply arrives token by token" src="__img2" />

## FAQ [#faq]

| Symptom                                                                                                                                     | Cause                                                    | Fix                                                                                         |
| ------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| Importing a package named `anthropic` fails at runtime (error pointing at a missing `node_modules/anthropic/index.js` or an invalid `main`) | You installed the unrelated npm placeholder of that name | Remove it and install the real one: uninstall `anthropic`, then install `@anthropic-ai/sdk` |
| 401 / invalid token                                                                                                                         | Key copied incompletely or missing from the environment  | Copy it again in full (mind the `sk-praxis-` prefix); check with `echo $env:PRAXIS_API_KEY` |
| 400 complaining about a missing `max_tokens`                                                                                                | The Anthropic protocol requires it                       | Add `max_tokens` (e.g. 256) to the `messages.create` call                                   |
| 400 `STREAMING_UNPROVEN`                                                                                                                    | That model route isn't streaming-enabled yet             | Drop streaming for a plain call, or retry with another model                                |
| "Model not found"                                                                                                                           | Model ID doesn't match the catalog                       | Copy the exact ID from [Console → Models](https://console.deepraxis.ai/models)              |

## Advanced [#advanced]

* **What did that call cost?** The Anthropic-protocol `usage` carries no price; see [Console → Usage & Billing](https://console.deepraxis.ai/usage) for per-call details, or use the [OpenAI SDK](/en/docs/cookbook/sdk/openai-sdk)—that path returns the cost directly in `usage.cost`
* **Switch models**: change the `model` field; fill `claude-opus-5` for the Claude flagship, and `deepseek-flash` always points at the latest Flash generation
* **Read the chain of thought**: on reasoning models, the `content` blocks with `type` `thinking` are the reasoning—read them if you need them

## Related recipes [#related-recipes]

* [OpenAI SDK](/en/docs/cookbook/sdk/openai-sdk) (the OpenAI-protocol sibling) · [LangChain](/en/docs/cookbook/sdk/langchain) · [Vercel AI SDK](/en/docs/cookbook/sdk/vercel-ai-sdk)
* Rather not write code? See [Cherry Studio](/en/docs/cookbook/chat-clients/cherry-studio) · [Claude Code](/en/docs/cookbook/coding-agents/claude-code)
