在请求中声明 tools,模型会在需要时返回 tool_calls,由你执行并把结果回传。
curl https://tokendog.io/v1/chat/completions \
-H "Authorization: Bearer $TOKENDOG_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model":"gpt-5",
"messages":[{"role":"user","content":"北京现在天气怎么样?"}],
"tools":[{"type":"function","function":{
"name":"get_weather",
"description":"查询某城市的当前天气",
"parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}
}}]
}'
模型返回 tool_calls 后,由你的代码执行函数,再把结果作为 role: "tool" 消息回传,模型据此生成最终答复。