Skip to content

Tool Calling

CompactifAI API’s chat completion endpoint supports function calling (tool calling), allowing you to integrate custom capabilities directly into the conversation flow for more dynamic and precise responses.

import requests
API_URL = "https://api.compactif.ai/v1/chat/completions"
API_KEY = "your_api_key_here"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
data = {
"messages": [
{
"role": "user",
"content": "What's the weather like in San Sebastián?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Respond only with a get_weather generated by a tool. Get the current weather in a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and state, e.g., 'San Sebastián'"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location", "unit"]
}
}
}
],
"tool_choice": "auto",
"model": "cai-llama-4-scout-slim"
}
response = requests.post(API_URL, headers=headers, json=data)
print(response.json())
FieldTypeDescription
modelstringID of the compressed model to use
messagesarrayArray of message objects
toolsarrayArray of tool objects defining available functions
tool_choicestringWhich function is called: “none”, “auto”,“required”, or specific function
{
"id": "chatcmpl-a7550b9e-83a2-4686-9f07-7000712eafdd",
"choices": [
{
"finish_reason": "tool_calls",
"index": 0,
"logprobs": null,
"message": {
"content": null,
"refusal": null,
"role": "assistant",
"annotations": null,
"audio": null,
"function_call": null,
"tool_calls": [
{
"id": "chatcmpl-tool-c57ce1b880b84f4a9b3ddd5856e99f39",
"function": {
"arguments":"{\"location\": \"San Sebasti\án\", \"unit\": \"celsius\"}",
"name": "get_weather"
},
"type": "function"
}
],
"reasoning_content": null
},
"stop_reason": null
}
],
"created": 1755007250,
"model": "cai-llama-4-scout-slim",
"object": "chat.completion",
"service_tier": null,
"system_fingerprint": null,
"usage": {
"completion_tokens": 13,
"prompt_tokens": 684,
"total_tokens": 697,
"completion_tokens_details": null,
"prompt_tokens_details": null
},
"prompt_logprobs": null,
"kv_transfer_params": null
}
Model NameModel IDFunction/Tool Calling Compatible?
DeepSeek R1 0528 Slim by CompactifAIcai-deepseek-r1-0528-slimNo
DeepSeek R1 0528deepseek-r1-0528No
Llama 4 Scout Slim by CompactifAIcai-llama-4-scout-slimYes
Llama 4 Scoutllama-4-scoutYes
Llama 3.3 70B Slim by CompactifAIcai-llama-3-3-70b-slimYes
Llama 3.3 70Bllama-3-3-70bYes
Llama 3.1 8B Slim by CompactifAIcai-llama-3-1-8b-slimYes
Llama 3.1 8B Slim Reasoning by CompactifAIcai-llama-3-1-8b-slim-rYes
Llama 3.1 8Bllama-3-1-8bYes
Mistral Small 3.1 Slim by CompactifAIcai-mistral-small-3-1-slimNo
Mistral Small 3.1mistral-small-3-1No
OpenAI GPT OSS 20Bgpt-oss-20bNo
OpenAI GPT OSS 120Bgpt-oss-120bNo
  • tool_choice can be set as a custom function (e.g. "tool_choice": {"type": "function", "function": {"name": "get_weather"}})
  • Tool calling for GPT and DeepSeek based models is a work in progress