Skip to main content

Function Calling

POST /v1/chat/completions
As of March 23, 2026, Crazyrouter production has verified that gpt-5.4 on the Chat Completions path returns tool_calls.

Step 1: Define the Tool

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": "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
          }
        }
      }
    ]
  }'
Observed production response shape:
{
  "object": "chat.completion",
  "model": "gpt-5.4",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "call_...",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"city\":\"Beijing\"}"
            }
          }
        ]
      }
    }
  ]
}

Step 2: Return the Tool Result

Once you receive tool_calls, send your tool result back as a role: "tool" message:
{
  "model": "gpt-5.4",
  "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
        }
      }
    }
  ]
}
This production pass confirmed the primary tool_calls path. It also observed that message.reasoning_content may appear as a key, but it should not be treated as a stable dependency for tool-calling flows.