curl https://api.pipellm.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $PIPELLM_API_KEY" \
-d '{
"model": "gpt-5",
"messages": [{"role": "user", "content": "你好"}]
}'
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["PIPELLM_API_KEY"],
base_url="https://api.pipellm.ai/v1",
)
print(client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": "你好"}],
).choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.PIPELLM_API_KEY,
baseURL: "https://api.pipellm.ai/v1",
});
const response = await client.chat.completions.create({
model: "gpt-5",
messages: [{ role: "user", content: "你好" }],
});
console.log(response.choices[0].message.content);
{
"id": "<string>",
"object": "<string>",
"model": "<string>",
"choices": [
{
"index": 123,
"message": {},
"delta": {},
"finish_reason": "<string>"
}
],
"usage": {}
}创建对话补全
为一段对话生成模型回复,支持流式输出。
POST
/
v1
/
chat
/
completions
curl https://api.pipellm.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $PIPELLM_API_KEY" \
-d '{
"model": "gpt-5",
"messages": [{"role": "user", "content": "你好"}]
}'
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["PIPELLM_API_KEY"],
base_url="https://api.pipellm.ai/v1",
)
print(client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": "你好"}],
).choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.PIPELLM_API_KEY,
baseURL: "https://api.pipellm.ai/v1",
});
const response = await client.chat.completions.create({
model: "gpt-5",
messages: [{ role: "user", content: "你好" }],
});
console.log(response.choices[0].message.content);
{
"id": "<string>",
"object": "<string>",
"model": "<string>",
"choices": [
{
"index": 123,
"message": {},
"delta": {},
"finish_reason": "<string>"
}
],
"usage": {}
}使用
Authorization: Bearer $PIPELLM_API_KEY。model 从 GET /v1/models 选取。
端点
POST https://api.pipellm.ai/v1/chat/completions
这条 free route 只接受 OpenAI 兼容格式请求,并只路由到 OpenAI 兼容平台。
如果你想保留 OpenAI 格式去调用 Anthropic 或 Gemini 模型,请使用
OpenAI Format Converter。
curl https://api.pipellm.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $PIPELLM_API_KEY" \
-d '{
"model": "gpt-5",
"messages": [{"role": "user", "content": "你好"}]
}'
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["PIPELLM_API_KEY"],
base_url="https://api.pipellm.ai/v1",
)
print(client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": "你好"}],
).choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.PIPELLM_API_KEY,
baseURL: "https://api.pipellm.ai/v1",
});
const response = await client.chat.completions.create({
model: "gpt-5",
messages: [{ role: "user", content: "你好" }],
});
console.log(response.choices[0].message.content);
代码示例
- cURL
- Python
- Node.js
- Go
curl https://api.pipellm.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $PIPELLM_API_KEY" \
-d '{
"model": "gpt-5",
"max_completion_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Why is the sky blue?"
}
]
}'
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv('PIPELLM_API_KEY'),
base_url='https://api.pipellm.ai/v1'
)
response = client.chat.completions.create(
model='gpt-5',
messages=[
{
'role': 'user',
'content': 'Why is the sky blue?'
}
]
)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.PIPELLM_API_KEY,
baseURL: 'https://api.pipellm.ai/v1'
});
const response = await client.chat.completions.create({
model: 'gpt-5',
messages: [
{
role: 'user',
content: 'Why is the sky blue?'
}
]
});
package main
import (
"context"
"os"
openai "github.com/sashabaranov/go-openai"
)
func main() {
config := openai.DefaultConfig(os.Getenv("PIPELLM_API_KEY"))
config.BaseURL = "https://api.pipellm.ai/v1"
client := openai.NewClientWithConfig(config)
resp, _ := client.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: "gpt-5",
Messages: []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleUser,
Content: "Why is the sky blue?",
},
},
},
)
}
请求参数
model 从 GET /v1/models 选取。原生 /v1/chat/completions 只会路由到 OpenAI 兼容平台。
string
必填
当前账号可见的模型 ID。
array
必填
number
采样温度,0–2。默认
1。integer
最大生成 token 数。
integer
较新的 OpenAI 兼容模型优先用这个字段,而不是
max_tokens。number
核采样,0–1。
integer
生成条数。默认
1。string | string[]
停止序列,或停止序列列表。
number
存在惩罚,-2 到 2。默认
0。number
频率惩罚,-2 到 2。默认
0。array
string | object
auto、none,或 {"type":"function","function":{"name":"..."}}。string
终端用户标识,用于滥用追踪。
响应格式
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": 1234567890,
"model": "gpt-5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The sky appears blue because..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 50,
"total_tokens": 60
}
}
string
补全 ID。
string
非流式为
chat.completion,流式为 chat.completion.chunk。string
实际生成用的模型。
array
object
Token 计数:
prompt_tokens、completion_tokens、total_tokens。错误
错误信封与 错误 相同。400 invalid_request_error
400 invalid_request_error
JSON 不合法、缺少
model / messages,或原生路由协议不匹配。{
"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
缺少或无效的 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
账号 RPM 超限。见 速率限制。
{
"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."
}
}
Function Calling
Function Calling 允许模型生成结构化的 JSON 来调用代码中的函数。- Python
- Node.js
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "获取指定地点的当前天气",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "城市名称"}
},
"required": ["location"]
}
}
}
]
response = client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": "东京现在天气怎么样?"}],
tools=tools,
tool_choice="auto"
)
if response.choices[0].message.tool_calls:
tool_call = response.choices[0].message.tool_calls[0]
# 执行你的函数并返回结果
const tools = [
{
type: "function",
function: {
name: "get_weather",
description: "获取指定地点的当前天气",
parameters: {
type: "object",
properties: {
location: { type: "string", description: "城市名称" }
},
required: ["location"]
}
}
}
];
const response = await client.chat.completions.create({
model: 'gpt-5',
messages: [{ role: 'user', content: '东京现在天气怎么样?' }],
tools: tools,
tool_choice: 'auto'
});
if (response.choices[0].message.tool_calls) {
const toolCall = response.choices[0].message.tool_calls[0];
// 执行你的函数并返回结果
}
Function Calling 官方文档
完整的函数定义和响应处理指南
此页面对您有帮助吗?