支持的模型
目前只有以下模型提供了 Anthropic SDK 兼容性支持:快速开始
1. 安装 Anthropic SDK
pip install anthropic
npm install @anthropic-ai/sdk
2. 初始化客户端
Anthropic SDK 会尝试从环境变量ANTHROPIC_API_KEY 和 ANTHROPIC_BASE_URL 中分别获取 API Key 和 base URL。您也可以在初始化客户端的时候通过参数来指定。
- 基于环境变量设置
export ANTHROPIC_BASE_URL="https://api.ppio.com/anthropic"
export ANTHROPIC_API_KEY="<PPIO 派欧云 API Key>"
- 通过在初始化 Anthropic 客户端时设置参数
import anthropic
client = anthropic.Anthropic(
base_url="https://api.ppio.com/anthropic",
api_key="<PPIO 派欧云 API Key>",
# 重写 header
default_headers={
"Content-Type": "application/json",
"Authorization": "Bearer <PPIO 派欧云 API Key>",
}
)
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
baseURL: "https://api.ppio.com/anthropic",
apiKey: "<PPIO 派欧云 API Key>",
// 重写 header
defaultHeaders: {
"Content-Type": "application/json",
Authorization: `Bearer <PPIO 派欧云 API Key>`,
}
});
3. 调用 API
import anthropic
# 初始化客户端,如果您已经通过环境变量 `ANTHROPIC_BASE_URL` 和 `ANTHROPIC_API_KEY`
# 设置了 API Key 和 base URL,可以省略 `api_key` 和 `base_url` 参数。
client = anthropic.Anthropic(
base_url="https://api.ppio.com/anthropic",
api_key="<PPIO 派欧云 API Key>",
# 重写 header
default_headers={
"Content-Type": "application/json",
"Authorization": "Bearer <PPIO 派欧云 API Key>",
}
)
message = client.messages.create(
model="moonshotai/kimi-k2-instruct",
max_tokens=1000,
temperature=1,
system=[
{
"type": "text",
"text": "你是 PPIO派欧云 AI 助手,你会以诚实专业的态度帮助用户,用中文回答问题。"
}
],
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "你是谁?"
}
]
}
]
)
print(message.content)
import Anthropic from "@anthropic-ai/sdk";
// 初始化客户端,如果您已经通过环境变量 `ANTHROPIC_BASE_URL` 和 `ANTHROPIC_API_KEY`
// 设置了 API Key 和 base URL,可以省略 `baseURL` 和 `apiKey` 参数。
const anthropic = new Anthropic({
baseURL: "https://api.ppio.com/anthropic",
apiKey: "<PPIO 派欧云 API Key>",
// 重写 header
defaultHeaders: {
"Content-Type": "application/json",
Authorization: `Bearer <PPIO 派欧云 API Key>`,
},
});
const msg = await anthropic.messages.create({
model: "moonshotai/kimi-k2-instruct",
max_tokens: 1000,
temperature: 1,
system: "你是 PPIO派欧云 AI 助手,你会以诚实专业的态度帮助用户,用中文回答问题。",
messages: [
{
role: "user",
content: [
{
type: "text",
text: "你是谁?"
}
]
}
]
});
console.log(msg);