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) |
OpenAI Python
Section titled “OpenAI Python”pip install openaiimport osfrom 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/v1export OPENAI_API_KEY=sk-xxxxOpenAI Node.js
Section titled “OpenAI Node.js”npm install openaiimport 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);Anthropic Python
Section titled “Anthropic Python”pip install anthropicimport osfrom 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.
Anthropic Node.js
Section titled “Anthropic Node.js”npm install @anthropic-ai/sdkimport 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);Common problems
Section titled “Common problems”- 404 / Invalid URL: the base URL has
/v1where 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.