更新日期:2026-06-23
Tool Calling
本文档只收录 已在 Crazyrouter 生产环境实际请求验证成功 的 Tool Calling 用法。
验证时间:
已验证模型:
gpt-5.5
claude-opus-4-8
gemini-3.1-pro
已验证能力矩阵
| 模型 | 协议 | 端点 | 成功标志 |
|---|
gpt-5.5 | OpenAI Chat Completions | POST /v1/chat/completions | 返回 tool_calls |
claude-opus-4-8 | Anthropic Messages | POST /v1/messages | 返回 tool_use block |
gemini-3.1-pro | Gemini Native | POST /v1beta/models/{model}:generateContent | 返回 functionCall |
Claude 工具调用当前按 Anthropic Messages 协议验证,也就是 POST /v1/messages 返回 tool_use block。不要把这一结论外推到 Claude 的 OpenAI 兼容 /v1/chat/completions 路径;在 Copilot、Continue、部分 VS Code Agent 或其他依赖工具调用的编程场景中,OpenAI 兼容端点可能无法拉起 Claude 原生工具调用。需要 Claude 编程 Agent 能力时,优先使用 Claude Code 或 Anthropic 原生客户端配置。
GPT-5.4
curl https://api.crazyrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-5.5",
"messages": [
{
"role": "user",
"content": "Use the get_time tool for Asia/Shanghai. Do not answer without calling the tool."
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_time",
"description": "Get the current time for a timezone",
"parameters": {
"type": "object",
"properties": {
"timezone": {
"type": "string"
}
},
"required": ["timezone"],
"additionalProperties": false
}
}
}
],
"tool_choice": "required"
}'
生产验证返回的关键字段:
{
"tool_calls": [
{
"type": "function",
"function": {
"name": "get_time",
"arguments": "{\"timezone\":\"Asia/Shanghai\"}"
}
}
]
}
Claude Sonnet 4.6
curl https://api.crazyrouter.com/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-opus-4-8",
"max_tokens": 256,
"tools": [
{
"name": "get_time",
"description": "Get the current time for a timezone",
"input_schema": {
"type": "object",
"properties": {
"timezone": {
"type": "string"
}
},
"required": ["timezone"]
}
}
],
"tool_choice": {
"type": "any"
},
"messages": [
{
"role": "user",
"content": "Use the get_time tool for Asia/Shanghai. Do not answer directly."
}
]
}'
生产验证返回的关键字段:
{
"stop_reason": "tool_use",
"content": [
{
"type": "tool_use",
"name": "get_time",
"input": {
"timezone": "Asia/Shanghai"
}
}
]
}
首轮联调建议:
- 对 Claude 原生
/v1/messages,优先显式加上 tool_choice
- 提示词里明确要求 “必须调用工具,不要直接回答”
- 这样更容易稳定复现
tool_use
Gemini 3 Pro
curl "https://api.crazyrouter.com/v1beta/models/gemini-3.1-pro:generateContent?key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Use the get_time function for Asia/Shanghai."
}
]
}
],
"tools": [
{
"functionDeclarations": [
{
"name": "get_time",
"description": "Get the current time for a timezone",
"parameters": {
"type": "object",
"properties": {
"timezone": {
"type": "string"
}
},
"required": ["timezone"]
}
}
]
}
]
}'
生产验证返回的关键字段:
{
"candidates": [
{
"content": {
"parts": [
{
"functionCall": {
"name": "get_time",
"args": {
"timezone": "Asia/Shanghai"
}
}
}
]
}
}
]
}
何时使用哪种协议
- 如果你的项目已经在使用 OpenAI SDK,优先用
gpt-5.5 的 OpenAI 兼容方式
- 如果你在做 Claude 原生接入,优先用
/v1/messages,并在首轮验证时加 tool_choice
- 如果你在做 Gemini 原生能力接入,优先用 Gemini Native API
相关文档