Anthropic SDK

Connect Praxis to the Anthropic SDK: swap the baseURL, keep your Claude code.

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

  • 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

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: 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 for the full flow.

  • Node.js 18 or newer (check node --version; Bun works too).

  • Install the SDK—note the package name is @anthropic-ai/sdk (the bare anthropic on npm is an unrelated placeholder):

    npm install @anthropic-ai/sdk

    Expected: the install succeeds.

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:

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:

node hello.mjs

Expected: a reply prints, followed by usage—at least input_tokens / output_tokens; 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.

The real output of the sample script in a terminal

Python version

pip install anthropic

Create hello.py:

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.

The real output of the Python sample

Streaming

Create stream.mjs:

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.

The streaming sample in a terminal: the reply arrives token by token

FAQ

SymptomCauseFix
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 nameRemove it and install the real one: uninstall anthropic, then install @anthropic-ai/sdk
401 / invalid tokenKey copied incompletely or missing from the environmentCopy it again in full (mind the sk-praxis- prefix); check with echo $env:PRAXIS_API_KEY
400 complaining about a missing max_tokensThe Anthropic protocol requires itAdd max_tokens (e.g. 256) to the messages.create call
400 STREAMING_UNPROVENThat model route isn't streaming-enabled yetDrop streaming for a plain call, or retry with another model
"Model not found"Model ID doesn't match the catalogCopy the exact ID from Console → Models

Advanced

  • What did that call cost? The Anthropic-protocol usage carries no price; see Console → Usage & Billing for per-call details, or use the 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
Export

On this page