API

Tool calling

Describe your functions in tools. When the model decides to call one, the response contains tool_calls and finish_reason is tool_calls.

Define tools

curl https://api.llm-hub.dev/v1/chat/completions \
  -H "Authorization: Bearer $LLMHUB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-sol",
    "messages": [{"role": "user", "content": "What is the weather in Paris?"}],
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city",
        "parameters": {
          "type": "object",
          "properties": {"city": {"type": "string"}},
          "required": ["city"]
        }
      }
    }]
  }'

Return the result

Run the function yourself, then append the assistant message with tool_calls and a tool message with the same tool_call_id, and call the endpoint again.

"messages": [
  {"role": "user", "content": "What is the weather in Paris?"},
  {"role": "assistant", "content": null, "tool_calls": [
    {"id": "call_123", "type": "function",
     "function": {"name": "get_weather", "arguments": "{\"city\":\"Paris\"}"}}
  ]},
  {"role": "tool", "tool_call_id": "call_123", "content": "{\"temp_c\": 18}"}
]

Tool support depends on the model. Anthropic Messages requests use the Anthropic tools / tool_use format instead.

Last updated