> ## 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.

# Function Calling

> 基于 2026-03-23 Crazyrouter 生产环境验证的 Chat Completions 工具调用

> 更新日期：2026-06-06

# Function Calling

```
POST /v1/chat/completions
```

截至 2026 年 3 月 23 日，Crazyrouter 生产环境已验证 `gpt-5.5` 在 Chat Completions 路径下会返回 `tool_calls`。

***

## 第一步：定义工具

```bash theme={null}
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": "What is the weather in Beijing? Use the tool."}
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "Get weather info for a city",
          "parameters": {
            "type": "object",
            "properties": {
              "city": {"type": "string"}
            },
            "required": ["city"],
            "additionalProperties": false
          }
        }
      }
    ]
  }'
```

生产环境实际返回的关键形态：

```json theme={null}
{
  "object": "chat.completion",
  "model": "gpt-5.5",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "call_...",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"city\":\"Beijing\"}"
            }
          }
        ]
      }
    }
  ]
}
```

***

## 第二步：回传工具结果

拿到 `tool_calls` 之后，把你的工具执行结果作为 `role: "tool"` 消息发回：

```json theme={null}
{
  "model": "gpt-5.5",
  "messages": [
    {"role": "user", "content": "What is the weather in Beijing? Use the tool."},
    {
      "role": "assistant",
      "content": null,
      "tool_calls": [
        {
          "id": "call_123",
          "type": "function",
          "function": {
            "name": "get_weather",
            "arguments": "{\"city\":\"Beijing\"}"
          }
        }
      ]
    },
    {
      "role": "tool",
      "tool_call_id": "call_123",
      "content": "{\"temperature\":22,\"condition\":\"sunny\"}"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get weather info for a city",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {"type": "string"}
          },
          "required": ["city"],
          "additionalProperties": false
        }
      }
    }
  ]
}
```

<Note>
  本轮生产验证确认了 `tool_calls` 这条主链路，同时也观察到 `message.reasoning_content` 这个键可能出现，但它不应作为当前工具调用流程的稳定依赖字段。
</Note>
