Overview

This documentation shows how to use tool calling of Confidential AI API to interact with external tools, such as APIs, databases, or other applications, to gather real-time information or perform actions beyond its pre-trained knowledge.

Supported Models

  • phala/deepseek-chat-v3-0324
  • phala/qwen3-coder
  • phala/llama-3.3-70b-instruct

Define the Tool

Use following request to create a function named 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"
}'
Extract the tool id from the response, and in this example it would be chatcmpl-tool-471f2c795ab64a27ab671a9e302c94db.

Invoke the Tool

Use the tool id extracted from previouse request to call the tool.
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"
  }'