跳转到主要内容
认证和模型列表请参考 概述

端点

POST https://api.pipellm.ai/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-4o",
    "max_completion_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "Why is the sky blue?"
      }
    ]
  }'

请求参数

参数类型必需描述
modelstring模型 ID(如 gpt-4ogrok-2
messagesarray消息对象数组
max_tokensinteger最大生成 token 数
temperaturenumber采样温度(0-2)
streamboolean启用流式响应

响应格式

{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "created": 1234567890,
  "model": "gpt-4o",
  "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
  }
}

Function Calling

Function Calling 允许模型生成结构化的 JSON 来调用代码中的函数。
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-4.1",
  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]
  # 执行你的函数并返回结果

Function Calling 官方文档

完整的函数定义和响应处理指南