Docs
Tool calling (function calling)
Let models call your functions via the OpenAI-compatible tools parameter. Works with existing SDKs — just switch the base URL.
Quick start
curl https://api.abliteration.ai/v1/chat/completions \
-H "Authorization: Bearer $ABLIT_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "abliterated-model",
"messages": [
{ "role": "user", "content": "Look up the status of order 123." }
],
"tools": [
{
"type": "function",
"function": {
"name": "get_order_status",
"description": "Lookup an order status by id.",
"parameters": {
"type": "object",
"properties": { "order_id": { "type": "string" } },
"required": ["order_id"]
}
}
}
]
}'Service notes
- Pricing model: Usage-based pricing (~$5 per 1M tokens) billed on total tokens (input + output). See the API pricing page for current plans.
- Data retention: No prompt/output retention by default. Operational telemetry (token counts, timestamps, error codes) is retained for billing and reliability.
- Compatibility: OpenAI-style /v1/chat/completions request and response format with a base URL switch.
- Latency: Depends on model size, prompt length, and load. Streaming reduces time-to-first-token.
- Throughput: Team plans include priority throughput. Actual throughput varies with demand.
- Rate limits: Limits vary by plan and load. Handle 429s with backoff and respect any Retry-After header.
How tool calling works
Tool calling follows a multi-step loop between your application and the model.
- 1. Define tools — Describe available functions with a JSON Schema in the
toolsarray. - 2. Send request — The model analyzes the user message and decides whether to call a tool.
- 3. Receive tool_calls — If the model invokes a tool, the response contains a
tool_callsarray instead of plain content. - 4. Execute function — Your code runs the function with the provided arguments.
- 5. Return result — Send the function result back in a message with
role: "tool"and the matchingtool_call_id. - 6. Get final answer — The model incorporates the tool result and returns a natural language response.
Tool definition schema
Each tool must specify type: "function" and a function object with name, description, and parameters (JSON Schema).
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
}Response with tool_calls
When the model invokes a tool, the response contains a tool_calls array with the function name and arguments as a JSON string.
{
"choices": [
{
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_order_status",
"arguments": "{\"order_id\": \"123\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
]
}Sending tool results back
After executing the function, append a tool-role message with the result. The tool_call_id must match the id from the original tool call.
curl https://api.abliteration.ai/v1/chat/completions \
-H "Authorization: Bearer $ABLIT_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "abliterated-model",
"messages": [
{ "role": "user", "content": "Look up the status of order 123." },
{
"role": "assistant",
"content": null,
"tool_calls": [{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_order_status",
"arguments": "{\"order_id\": \"123\"}"
}
}]
},
{
"role": "tool",
"tool_call_id": "call_abc123",
"content": "{\"status\": \"shipped\", \"tracking\": \"1Z999AA10\"}"
}
]
}'Multiple tools
Define multiple tools in one request. The model may call one, several, or none. Execute each and return all results before the next call.
{
"model": "abliterated-model",
"messages": [
{ "role": "user", "content": "What's the weather in NYC and order status for 456?" }
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a location.",
"parameters": {
"type": "object",
"properties": {
"location": { "type": "string" }
},
"required": ["location"]
}
}
},
{
"type": "function",
"function": {
"name": "get_order_status",
"description": "Lookup an order status by id.",
"parameters": {
"type": "object",
"properties": {
"order_id": { "type": "string" }
},
"required": ["order_id"]
}
}
}
]
}Forcing a specific tool call
Use tool_choice to control invocation: "auto" (default), "none", or force a specific function.
{
"model": "abliterated-model",
"messages": [
{ "role": "user", "content": "Tell me about order 789." }
],
"tools": [ ... ],
"tool_choice": {
"type": "function",
"function": { "name": "get_order_status" }
}
}Best practices
Guidelines for reliable tool calling.
- Write clear, specific
descriptionfields so the model knows when to call each function. - Use
requiredin your JSON Schema to mark mandatory parameters. - Always validate and parse
argumentsas JSON before executing the function — the model may produce malformed output in edge cases. - Return structured JSON in tool results so the model can interpret them consistently.
- Keep tool result payloads concise. Large payloads consume tokens and may degrade response quality.
- Use
tool_choice: "none"when you want the model to respond without calling any tools. - Handle the case where
tool_callsis empty or absent — the model may answer directly without invoking a tool.
Common errors & fixes
- 400 Bad Request: Verify that each tool has type: "function" and a valid JSON Schema in parameters.
- 400 Invalid tool_call_id: The tool_call_id in the tool-role message must match the id returned in the assistant's tool_calls.
- 401 Unauthorized: Check that your API key is set and sent as a Bearer token.
- 429 Rate limit: Back off and retry. Use the Retry-After header for pacing.