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": "carina-60b"
}
response = requests.post(API_URL, headers=headers, json=data)
print(response.json())
Field Type Description
model string ID of the compressed model to use
messages array Array of message objects
tools array Array of tool objects defining available functions
tool_choice string Which 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": "carina-60b",
"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 Name Model ID Function/Tool Calling Compatible?
GLM 5.2 glm-5-2 Yes
GLM 5.3 glm-5-3 Yes
Quasar 2 358B quasar-2-358b Yes
Carina 60B carina-60b Yes
Qwen 3.8 27B qwen-3-8-27b Yes
  • tool_choice can be set as a custom function (e.g. "tool_choice": {"type": "function", "function": {"name": "get_weather"}})