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 '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "你好"}]
}'
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["PIPELLM_API_KEY"],
base_url="https://api.pipellm.ai",
)
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "你好"}],
)
print(message.content[0].text)
{
"id": "<string>",
"type": "<string>",
"role": "<string>",
"content": [
{}
],
"stop_reason": "<string>",
"usage": {}
}创建消息
使用 Anthropic Messages API 创建消息。
POST
/
v1
/
messages
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 '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "你好"}]
}'
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["PIPELLM_API_KEY"],
base_url="https://api.pipellm.ai",
)
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "你好"}],
)
print(message.content[0].text)
{
"id": "<string>",
"type": "<string>",
"role": "<string>",
"content": [
{}
],
"stop_reason": "<string>",
"usage": {}
}使用
x-api-key: $PIPELLM_API_KEY 和 anthropic-version: 2023-06-01。原生 /v1/messages 只会路由到 Anthropic 兼容平台。
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 '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "你好"}]
}'
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["PIPELLM_API_KEY"],
base_url="https://api.pipellm.ai",
)
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "你好"}],
)
print(message.content[0].text)
string
必填
Anthropic 模型 ID,从
GET /v1/models 选取。array
必填
integer
必填
最大输出 token 数。
string | array
系统提示。
number
采样温度,0–1。
number
核采样。
integer
Top-k 采样。
boolean
为
true 时返回 SSE。string[]
自定义停止序列。
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?")),
}),
})
}
响应格式
{
"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
}
}
string
消息 ID。
string
固定为
message。string
固定为
assistant。array
输出块。文本回复是
{ "type": "text", "text": "..." }。工具调用是 tool_use 块。string
end_turn、max_tokens 或 tool_use。object
input_tokens 和 output_tokens。错误
错误信封与 错误 相同。原生/v1/messages 在请求体不是 Anthropic 格式时也会返回 400。
400 invalid_request_error
400 invalid_request_error
缺少
model、messages 或 max_tokens,或协议不匹配。{
"error": {
"type": "invalid_request_error",
"code": "400",
"message": "The 'model' field is required but was not provided in the request"
}
}
401 authentication_error
401 authentication_error
缺少或无效的
x-api-key。{
"error": {
"type": "authentication_error",
"code": "401",
"message": "Incorrect API key provided. Please visit https://console.pipellm.ai/account/api-keys to find your API key."
}
}
402 insufficient_balance
402 insufficient_balance
{
"error": {
"type": "insufficient_balance",
"code": "402",
"message": "Insufficient balance. Please recharge your account at https://console.pipellm.ai/billing."
}
}
429 rate_limit_error
429 rate_limit_error
见 速率限制。
{
"error": {
"type": "rate_limit_error",
"code": "429",
"message": "Rate limit exceeded. Your current limit is 120 requests per minute (approximately 2.00 requests per second). Please visit https://console.pipellm.ai/billing to upgrade your plan for higher limits."
}
}
相关文档
路由与协议
查看原生路由约束和 converter 路由
Anthropic 概述
查看 Header、模型和路由族说明
Anthropic Format Converter
保留 Anthropic 格式,调用其他协议族模型
此页面对您有帮助吗?