Endpoint
POST https://api.pipellm.ai/v1/messages
这条 free route 只接受 Anthropic Messages 格式请求,并只路由到 Anthropic
兼容平台。如果你想保留 Anthropic 格式去调用 OpenAI 或 Gemini 模型,请使用
Anthropic Format Converter。
安装 SDK
- Python
- Node.js
- Go
pip install anthropic
npm install @anthropic-ai/sdk
go get github.com/anthropics/anthropic-sdk-go
代码示例
- cURL
- Python
- Node.js
- Go
curl https://api.pipellm.ai/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: $PIPELLM_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d @- << 'EOF'
{
"model": "claude-sonnet-4-5-20250929",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Why is the sky blue?"}
]
}
EOF
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.getenv('PIPELLM_API_KEY'),
base_url='https://api.pipellm.ai'
)
message = client.messages.create(
model='claude-sonnet-4-5-20250929',
max_tokens=1024,
messages=[
{'role': 'user', 'content': 'Why is the sky blue?'}
]
)
print(message.content[0].text)
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: process.env.PIPELLM_API_KEY,
baseURL: 'https://api.pipellm.ai'
});
const message = await client.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
messages: [
{ role: 'user', content: 'Why is the sky blue?' }
]
});
console.log(message.content[0].text);
package main
import (
"context"
"os"
"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
)
func main() {
client := anthropic.NewClient(
option.WithAPIKey(os.Getenv("PIPELLM_API_KEY")),
option.WithBaseURL("https://api.pipellm.ai"),
)
message, _ := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.F("claude-sonnet-4-5-20250929"),
MaxTokens: anthropic.Int(1024),
Messages: anthropic.F([]anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("Why is the sky blue?")),
}),
})
}
请求参数
| 参数 | 类型 | 必需 | 描述 |
|---|---|---|---|
model | string | 是 | 模型 ID(如 claude-sonnet-4-5-20250929) |
messages | array | 是 | 消息对象数组 |
max_tokens | integer | 是 | 最大生成 token 数 |
temperature | number | 否 | 采样温度(0-1) |
stream | boolean | 否 | 启用流式响应 |
响应格式
{
"id": "msg_xxx",
"type": "message",
"role": "assistant",
"content": [
{"type": "text", "text": "The sky appears blue because..."}
],
"model": "claude-sonnet-4-5-20250929",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 10,
"output_tokens": 50
}
}
相关文档
路由与协议
查看原生路由约束和 converter 路由
Anthropic 概述
查看 Header、模型和路由族说明
Anthropic Format Converter
保留 Anthropic 格式,调用其他协议族模型