联网搜索 (Web Search)
内置联网搜索能力,让 Kimi 能够获取实时网络信息来回答问题。
API 端点
POST
/chat/completions使用联网搜索的对话
请求参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 必填 | 支持联网搜索的模型 |
messages | array | 必填 | 对话消息 |
tools | array | 可选 | 工具列表,包含 web_search |
请求示例
请求示例
{
"model": "kimi-k2.5",
"messages": [
{
"role": "user",
"content": "请搜索一下今天的科技新闻"
}
],
"tools": [
{
"type": "builtin_function",
"function": {
"name": "web_search"
}
}
]
}响应示例
响应示例
{
"id": "chatcmpl-789",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "根据最新搜索结果,今天的主要科技新闻包括..."
},
"finish_reason": "stop"
}
]
}代码示例
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://kimi-api.com/v1"
)
response = client.chat.completions.create(
model="kimi-k2.5",
messages=[
{"role": "user", "content": "请搜索一下今天的科技新闻"}
],
tools=[
{
"type": "builtin_function",
"function": {
"name": "web_search"
}
}
]
)
print(response.choices[0].message.content)