功能指南
工具调用
编程 Agent(Claude Code、OpenCode、Cline 等)靠工具调用读写文件、执行命令。只有部分模型支持。
哪些模型支持
当前支持工具调用的模型:gemma-4-uncensored、deepseek-v4-1-flash-uncensored、qwen/qwen3.8-27b-uncensored、olafangensan-glm-4.7-flash-heretic、z-ai/glm-5.3-flash-uncensored、z-ai/glm-5.3-uncensored、deepseek-v4-1-flash。
GET /v1/models?type=chat 返回的 supportsTools 为 true 的就是。给不支持的模型传 tools,会得到 400:
{"error": {"code": "VALIDATION_ERROR", "message": "模型 <模型 id> 不支持工具调用。支持工具调用的模型:…", "details": {"field": "tools"}}}OpenAI 格式:一次完整往返
第一步,带上工具定义发问:
curl https://api.sichang.xyz/v1/chat/completions \
-H "Authorization: Bearer $SICHANG_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "<模型 id>",
"messages": [{"role": "user", "content": "北京现在天气怎么样?"}],
"tools": [{"type": "function", "function": {
"name": "get_weather",
"description": "查询城市当前天气",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}
}}]
}'模型决定调用工具时,finish_reason 是 tool_calls,参数在 message.tool_calls:
"tool_calls": [{"id": "call_1", "type": "function",
"function": {"name": "get_weather", "arguments": "{\"city\": \"北京\"}"}}]第二步,执行工具,把结果作为 role: tool 消息追加回去(tool_call_id 对应上一步的 id),连同原来的 tools 再发一次:
"messages": [
{"role": "user", "content": "北京现在天气怎么样?"},
{"role": "assistant", "content": null, "tool_calls": [{"id": "call_1", "type": "function",
"function": {"name": "get_weather", "arguments": "{\"city\":\"北京\"}"}}]},
{"role": "tool", "tool_call_id": "call_1", "content": "{\"temp\":18,\"sky\":\"晴\"}"}
]模型据此给出最终回答,finish_reason 变回 stop。
支持的字段:tools(只支持 type: function,最多 128 个,工具名为非空字符串、至多 256 个字符,原样转发给模型)、tool_choice(auto、none、required 或指定函数)、parallel_tool_calls。旧版的 functions / function_call 不支持,请改用 tools。
个别模型单次接受的工具数更少,超出时返回 400(field 为 tools),错误信息里写明该模型的上限。
工具名可以带 .、:、/ 等字符(如 MCP 风格的 server.tool),模型回调时使用原名。少数模型服务只接受字母、数字、下划线和连字符,遇到这种情况会返回 400,错误信息里附有模型服务的原话,按提示改名即可。
Anthropic 格式
/v1/messages 接受 Anthropic 标准的 tools(name + input_schema)与 tool_choice(auto、any、tool、none),返回 tool_use 内容块,结果用 tool_result 块回传。Claude Code 用的就是这一套。
Anthropic 的网页搜索工具(web_search_*)由思畅代为执行,回复里是标准的 server_tool_use 与 web_search_tool_result 块,max_uses 上限 3,计费同 web_search_options。其余服务端工具会被忽略。
内容审核与工具结果
内容审核只看用户消息,工具返回的结果(代码、命令输出)不参与审核,不会因为代码里的关键词被误拦。