Documentation Index
Fetch the complete documentation index at: https://docs.crazyrouter.com/llms.txt
Use this file to discover all available pages before exploring further.
Tool Calling
本文档只收录 已在 Crazyrouter 生产环境实际请求验证成功 的 Tool Calling 用法。
验证时间:
已验证模型:
gpt-5.4
claude-sonnet-4-6
gemini-3-pro
已验证能力矩阵
| 模型 | 协议 | 端点 | 成功标志 |
|---|
gpt-5.4 | OpenAI Chat Completions | POST /v1/chat/completions | 返回 tool_calls |
claude-sonnet-4-6 | Anthropic Messages | POST /v1/messages | 返回 tool_use block |
gemini-3-pro | Gemini Native | POST /v1beta/models/{model}:generateContent | 返回 functionCall |
GPT-5.4
curl https://crazyrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-5.4",
"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://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-sonnet-4-6",
"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://crazyrouter.com/v1beta/models/gemini-3-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.4 的 OpenAI 兼容方式
- 如果你在做 Claude 原生接入,优先用
/v1/messages,并在首轮验证时加 tool_choice
- 如果你在做 Gemini 原生能力接入,优先用 Gemini Native API
相关文档