Skip to content

OpenAI / Anthropic SDKs

The official SDKs all let you set a custom base URL. You only need to change two settings: the base URL and the API key.

SDK Base URL
OpenAI SDK https://api.openpalmlab.com/v1
Anthropic SDK https://api.openpalmlab.com (no /v1; the SDK adds it)
终端窗口
pip install openai
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.openpalmlab.com/v1",
api_key=os.environ["OPENPALMLAB_API_KEY"],
)
resp = client.chat.completions.create(
model="YOUR_MODEL",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)

Or leave the code alone and set environment variables:

终端窗口
export OPENAI_BASE_URL=https://api.openpalmlab.com/v1
export OPENAI_API_KEY=sk-xxxx
终端窗口
npm install openai
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.openpalmlab.com/v1',
apiKey: process.env.OPENPALMLAB_API_KEY,
});
const resp = await client.chat.completions.create({
model: 'YOUR_MODEL',
messages: [{ role: 'user', content: 'Hello' }],
});
console.log(resp.choices[0].message.content);
终端窗口
pip install anthropic
import os
from anthropic import Anthropic
client = Anthropic(
base_url="https://api.openpalmlab.com",
api_key=os.environ["OPENPALMLAB_API_KEY"],
)
msg = client.messages.create(
model="YOUR_MODEL",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)

The matching environment variables are ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY.

终端窗口
npm install @anthropic-ai/sdk
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
baseURL: 'https://api.openpalmlab.com',
apiKey: process.env.OPENPALMLAB_API_KEY,
});
const msg = await client.messages.create({
model: 'YOUR_MODEL',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello' }],
});
console.log(msg.content[0].text);
  • 404 / Invalid URL: the base URL has /v1 where it should not, or is missing it. The OpenAI SDK needs /v1; the Anthropic SDK does not.
  • 401 Invalid token: the token is wrong, expired or out of quota. See Troubleshooting.
  • Model not available: the model name must match the pricing page exactly, including case and any date suffix.