API reference

Tool calling

Function calling with Abliterator's abliterated models in OpenAI and Anthropic formats: full tool loops in Python, tool_choice rules, streaming and parallel calls.

Reviewed APIToolsAgents

Quick answer

Both models support function calling in the OpenAI tools format and the Anthropic tool_use format. Send tools, run the calls the model asks for, and return the results. On kimi-k3.1-pro-abliterated with reasoning on, use tool_choice auto, none or required, not a named tool.

How it works

You describe tools with JSON Schema. The model decides whether to call one and returns the tool name and arguments. Your code runs the tool and sends the result back. The model then answers or calls another tool. Abliterator passes tools, tool_choice and parallel_tool_calls to the model unchanged.

The examples below give the model one tool, lookup_cve, that returns details for a CVE ID. In real code it would query your vulnerability database or the NVD API.

OpenAI format

import json
import os

from openai import OpenAI

client = OpenAI(base_url="https://abliterator.ai/v1", api_key=os.environ["ABL_API_KEY"])
MODEL = "kimi-k3.1-pro-abliterated"

tools = [
    {
        "type": "function",
        "function": {
            "name": "lookup_cve",
            "description": "Get the CVSS score, affected product and summary for a CVE ID.",
            "parameters": {
                "type": "object",
                "properties": {"cve_id": {"type": "string", "description": "For example CVE-2021-44228"}},
                "required": ["cve_id"],
            },
        },
    }
]


def lookup_cve(cve_id):
    # Replace with a real lookup.
    return {"cve_id": cve_id, "cvss": 10.0, "product": "Apache Log4j 2", "summary": "JNDI lookup in log messages allows remote code execution."}


messages = [
    {"role": "system", "content": "You triage vulnerabilities for an internal security team. Use tools for facts."},
    {"role": "user", "content": "Is CVE-2021-44228 something we should patch this week? We run Java services."},
]

while True:
    response = client.chat.completions.create(
        model=MODEL, max_tokens=8192, messages=messages, tools=tools, tool_choice="auto"
    )
    message = response.choices[0].message
    if not message.tool_calls:
        print(message.content)
        break
    messages.append(message.model_dump(exclude_none=True))
    for call in message.tool_calls:
        args = json.loads(call.function.arguments)
        result = lookup_cve(**args)
        messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)})

Notes:

  • Append the assistant message with its tool_calls before the tool results, and give each result the matching tool_call_id.
  • finish_reason is tool_calls when the model wants tools run.
  • call.function.arguments is a JSON string. Parse it, and validate it before acting on it: the model can produce arguments that do not match your schema.
  • The model may return several tool calls in one turn. Set parallel_tool_calls: false if your tools must run one at a time.

Anthropic format

import json
import os

import anthropic

client = anthropic.Anthropic(base_url="https://abliterator.ai", api_key=os.environ["ABL_API_KEY"])
MODEL = "kimi-k3.1-pro-abliterated"

tools = [
    {
        "name": "lookup_cve",
        "description": "Get the CVSS score, affected product and summary for a CVE ID.",
        "input_schema": {
            "type": "object",
            "properties": {"cve_id": {"type": "string", "description": "For example CVE-2021-44228"}},
            "required": ["cve_id"],
        },
    }
]


def lookup_cve(cve_id):
    # Replace with a real lookup.
    return {"cve_id": cve_id, "cvss": 10.0, "product": "Apache Log4j 2", "summary": "JNDI lookup in log messages allows remote code execution."}


messages = [{"role": "user", "content": "Is CVE-2021-44228 something we should patch this week? We run Java services."}]

while True:
    response = client.messages.create(
        model=MODEL,
        max_tokens=8192,
        system="You triage vulnerabilities for an internal security team. Use tools for facts.",
        tools=tools,
        messages=messages,
    )
    if response.stop_reason != "tool_use":
        print("".join(block.text for block in response.content if block.type == "text"))
        break
    messages.append({"role": "assistant", "content": response.content})
    results = []
    for block in response.content:
        if block.type == "tool_use":
            output = lookup_cve(**block.input)
            results.append({"type": "tool_result", "tool_use_id": block.id, "content": json.dumps(output)})
    messages.append({"role": "user", "content": results})

Notes:

  • Send the assistant's whole content back, including any thinking blocks, before your tool_result blocks.
  • stop_reason is tool_use when the model wants tools run.
  • block.input is already parsed JSON.

tool_choice

Value (OpenAI / Anthropic) Effect Works on
"auto" / {"type": "auto"} The model decides Both models
"none" / {"type": "none"} No tool calls Both models
"required" / {"type": "any"} Must call some tool Both models
{"type": "function", "function": {"name": "..."}} / {"type": "tool", "name": "..."} Must call that tool deepseek-v4.1-flash-abliterated; kimi-k3.1-pro-abliterated only with reasoning off

kimi-k3.1-pro-abliterated rejects a named tool while reasoning is on, with 400 tool_choice 'specified' is incompatible with thinking enabled. Either send reasoning_effort: "none" (Anthropic: "thinking": {"type": "disabled"}) with the named choice, or use "required" with a single tool. Some libraries use a named tool to get structured output, for example LangChain's with_structured_output in function-calling mode; see structured outputs for alternatives.

Streaming tool calls

In a Chat Completions stream, tool calls arrive in pieces in choices[0].delta.tool_calls. The first piece for each call has its index, id and function.name; later pieces append to function.arguments. Join the pieces by index, and parse the arguments after the chunk with finish_reason: "tool_calls". The SDKs' stream helpers do this for you.

In a Messages stream, a tool_use block streams its input as input_json_delta events. See streaming.

Tips

  • Keep tool definitions stable and first. Tools are part of the prompt prefix. Changing their order or text between requests causes prompt-cache misses. See prompt caching.
  • Leave room in max_tokens. Reasoning happens before each tool call and counts toward the limit.
  • Write precise descriptions. Say what the tool returns and when to use it.
  • Treat tool output as data. A fetched web page or a file can contain instructions. Tell the model in the system prompt that tool results are untrusted input; see system prompts.
  • Limit what tools can do. An abliterated model follows instructions more readily than a model trained to refuse. Give agents least-privilege tools, require confirmation for destructive actions, and keep the acceptable use policy in mind for anything that touches systems you do not own.