Skip to content

Tool Use (Function Calling)

Fresh

Let Mercury 2 call functions to build complex, multi-step responses.

How It Works

Define Tools

bash
curl https://api.inceptionlabs.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $INCEPTION_API_KEY" \
  -d '{
    "model": "mercury-2",
    "messages": [
      {"role": "user", "content": "What is the weather in San Francisco?"}
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "Get the current weather for a location",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "City name"
              },
              "unit": {
                "type": "string",
                "enum": ["celsius", "fahrenheit"],
                "description": "Temperature unit"
              }
            },
            "required": ["location"]
          }
        }
      }
    ]
  }'

Python Example

python
import os
import requests
import json

def get_weather(location, unit="celsius"):
    # Your actual weather API call here
    return {"temp": 22, "condition": "Sunny", "unit": unit}

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get current weather for a location",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {"type": "string", "description": "City name"},
                "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
            },
            "required": ["location"]
        }
    }
}]

response = requests.post(
    "https://api.inceptionlabs.ai/v1/chat/completions",
    headers={
        "Content-Type": "application/json",
        "Authorization": f"Bearer {os.environ['INCEPTION_API_KEY']}"
    },
    json={
        "model": "mercury-2",
        "messages": [{"role": "user", "content": "What's the weather in Tokyo?"}],
        "tools": tools
    }
)
print(json.dumps(response.json(), indent=2))

Tool Definition Schema

FieldTypeRequiredDescription
typestringYesAlways "function"
function.namestringYesFunction identifier
function.descriptionstringYesWhat the function does
function.parametersobjectYesJSON Schema for function params

See Also