Skip to main content

Use the Anthropic SDK

Choose a Messages-compatible offering in Anthropic SDK Setup. Configure the client with the host base URL; it appends /v1/messages. Pin the documented Messages version below because SDK defaults can change.

Set PRIMEX_API_KEY and PRIMEX_MODEL in your trusted application environment. Use the exact offering ID from Setup. The model's creator does not independently establish Messages or client-feature support.

Python​

Shell
python -m pip install anthropic
Python
import os
from anthropic import Anthropic

client = Anthropic(
api_key=os.environ["PRIMEX_API_KEY"],
base_url="https://gateway.primexos.com",
default_headers={"anthropic-version": "2023-06-01"},
timeout=60,
max_retries=0,
)
response = client.messages.create(
model=os.environ["PRIMEX_MODEL"],
max_tokens=128,
messages=[{"role": "user", "content": "Say hello in one line."}],
)
for block in response.content:
if block.type == "text":
print(block.text)

Node.js​

Shell
npm install @anthropic-ai/sdk

Save as hello.mjs and run node hello.mjs:

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

const client = new Anthropic({
apiKey: process.env.PRIMEX_API_KEY,
baseURL: "https://gateway.primexos.com",
defaultHeaders: { "anthropic-version": "2023-06-01" },
timeout: 60_000,
maxRetries: 0,
});
const response = await client.messages.create({
model: process.env.PRIMEX_MODEL,
max_tokens: 128,
messages: [{ role: "user", content: "Say hello in one line." }],
});
for (const block of response.content) {
if (block.type === "text") console.log(block.text);
}

These short text examples wait up to 60 seconds and disable automatic retries. A timeout can leave the outcome uncertain; check Usage before sending the request again. Choose operation-specific deadlines and retry behavior with the Production guide.

Verify and extend​

Expect a successful Messages response with text content blocks. Find the request in Usage. Other content blocks, such as tool use, need their own handling; see Messages, streaming and tool calling.

Do not infer coding-agent compatibility from an SDK text response. Use the Claude Code or Cline guide for their documented scope. Read the official SDK guidance and Primex Production guide before expanding traffic.