Quick guide for how to tool calling (or function calling) of Confidential AI API.
get_weather
curl -s -X POST 'https://api.redpill.ai/v1/chat/completions' \ -H 'Authorization: Bearer sk-xx' \ -H 'Content-Type: application/json' \ -d '{ "messages": [ { "content": "What is the weather like in New York?", "role": "user" } ], "tools": [ { "type": "function", "function": { "name": "get_weather", "description": "Get the current weather in a specified city", "parameters": { "type": "object", "properties": { "city": {"type": "string"}, "metric": {"type": "string", "enum": ["celsius", "fahrenheit"]} }, "required": ["city"] } } } ], "tool_choice": "auto", "stream": false, "model": "phala/qwen3-coder" }'
Example response of tool calling request
{ "id": "chatcmpl-28f745c2b7ee44f2ba36a8b4b409c74a", "object": "chat.completion", "created": 1754381277, "model": "qwen/qwen3-coder", "choices": [ { "index": 0, "message": { "role": "assistant", "content": null, "refusal": null, "annotations": null, "audio": null, "function_call": null, "tool_calls": [ { "id": "chatcmpl-tool-471f2c795ab64a27ab671a9e302c94db", "type": "function", "function": { "name": "get_weather", "arguments": "{\"city\": \"New York\", \"metric\": \"celsius\"}" } } ], "reasoning_content": null }, "logprobs": null, "finish_reason": "tool_calls", "stop_reason": null } ], "service_tier": null, "system_fingerprint": null, "usage": { "prompt_tokens": 319, "total_tokens": 353, "completion_tokens": 34, "prompt_tokens_details": null }, "prompt_logprobs": null, "kv_transfer_params": null }
chatcmpl-tool-471f2c795ab64a27ab671a9e302c94db
curl -s -X POST 'https://api.redpill.ai/v1/chat/completions' \ -H 'Authorization: Bearer sk-xx' \ -H 'Content-Type: application/json' \ -d '{ "messages": [ {"role": "user", "content": "What is the weather like in New York?"}, { "role": "assistant", "content": null, "tool_calls": [ { "id": "chatcmpl-tool-471f2c795ab64a27ab671a9e302c94db", "type": "function", "function": { "name": "get_weather", "arguments": "{\"city\": \"New York\", \"metric\": \"celsius\"}" } } ] }, { "role": "tool", "content": "{\"city\": \"New York\", \"temperature\": 15, \"description\": \"clear sky\", \"metric\": \"celsius\"}", "tool_call_id": "chatcmpl-tool-471f2c795ab64a27ab671a9e302c94db" } ], "tools": [ { "type": "function", "function": { "name": "get_weather", "description": "Get the current weather in a specified city", "parameters": { "type": "object", "properties": { "city": {"type": "string"}, "metric": {"type": "string", "enum": ["celsius", "fahrenheit"]} }, "required": ["city"] } } } ], "tool_choice": "auto", "stream": false, "model": "phala/qwen3-coder" }'
Example response of invoke the tool
{ "id": "chatcmpl-a46eff3d335c42c39bbe4ea69fc97462", "object": "chat.completion", "created": 1754381325, "model": "qwen/qwen3-coder", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "The current weather in New York is clear sky with a temperature of 15°C.", "refusal": null, "annotations": null, "audio": null, "function_call": null, "tool_calls": [], "reasoning_content": null }, "logprobs": null, "finish_reason": "stop", "stop_reason": null } ], "service_tier": null, "system_fingerprint": null, "usage": { "prompt_tokens": 394, "total_tokens": 413, "completion_tokens": 19, "prompt_tokens_details": null }, "prompt_logprobs": null, "kv_transfer_params": null }
Was this page helpful?