• Playground
  • Models
  • Rankings
  • Pricing
  • Support
Docs
  • About Boundless
  • Quickstart
  • API Compatibility
  • Models
  • OpenAI SDK
  • Anthropic SDK
  • Vercel AI SDK
  • LangChain
  • Streaming
  • Tool calling
  • Reasoning
  • Errors
  • MPP & Agentic Payments
  • Credits & Billing
  • Rate Limits
  • Teams
  • Privacy & ZDR
  • FAQ
  • Coding agents
    Coding Agents & Harnesses
  • Claude Code
  • Claude Desktop
  • Codex CLI
  • Codex app
  • OpenCode
  • Cursor
  • Cline
  • GitHub Copilot
  • Kilo Code
  • Qwen Code
  • Amp
  • CodeBuddy
  • Hermes
  • Hermes Desktop
  • JetBrains AI & Junie
  • Cherry Studio
  • Mastra
  • MiMo Code
  • Muse
  • omp (Oh My Pi)
  • OpenClaw
  • OpenHands
  • T3 Code
  • Advanced
    System One
All systems operational
© 2026 BoundlessTermssupport@boundless.network

Tool calling

Define function tools, assemble streamed tool-call arguments, and return the result to the model.

Tool calling works on chat completions, Responses and Messages. Pass your functions in tools. The model answers with the call it wants to make. You run it, then send the result back.

Not every model supports tools. GET /v1/model/info lists the capability flags for each model.

Example#

This example forces one tool call, assembles streamed arguments, returns the local result, then streams the final answer. The last chunk carries exact token counts.

import json
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["BOUNDLESS_API_KEY"],
    base_url="https://api.inference.boundless.network/v1",
)
messages = [{"role": "user", "content": "What is 20 + 22? Use the add tool."}]
tools = [{
    "type": "function",
    "function": {
        "name": "add",
        "description": "Add two integers.",
        "parameters": {
            "type": "object",
            "properties": {
                "a": {"type": "integer"},
                "b": {"type": "integer"},
            },
            "required": ["a", "b"],
            "additionalProperties": False,
        },
    },
}]

stream = client.chat.completions.create(
    model="deepseek/deepseek-v4.1-flash",
    messages=messages,
    max_tokens=1024,
    tools=tools,
    tool_choice={"type": "function", "function": {"name": "add"}},
    stream=True,
    stream_options={"include_usage": True},
)

tool_call = {"id": "", "type": "function", "function": {"name": "", "arguments": ""}}
for chunk in stream:
    if chunk.usage:
        print(f"first request: {chunk.usage}")
    if not chunk.choices:
        continue
    for delta_call in chunk.choices[0].delta.tool_calls or []:
        if delta_call.id:
            tool_call["id"] = delta_call.id
        if delta_call.function.name:
            tool_call["function"]["name"] = delta_call.function.name
        if delta_call.function.arguments:
            tool_call["function"]["arguments"] += delta_call.function.arguments

arguments = json.loads(tool_call["function"]["arguments"])
messages.extend([
    {"role": "assistant", "tool_calls": [tool_call]},
    {
        "role": "tool",
        "tool_call_id": tool_call["id"],
        "content": json.dumps({"result": arguments["a"] + arguments["b"]}),
    },
])

stream = client.chat.completions.create(
    model="deepseek/deepseek-v4.1-flash",
    messages=messages,
    max_tokens=1024,
    tools=tools,
    stream=True,
    stream_options={"include_usage": True},
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
    if chunk.usage:
        print(f"\nfinal request: {chunk.usage}")

How it works#

  • The model sends the call in delta.tool_calls. The id and the function name arrive first. The arguments string arrives in pieces. Join the pieces, then parse the JSON once the stream ends.
  • Send the result back as a message with role set to tool and the same tool_call_id. Keep the assistant message that made the call in the history.
  • tool_choice forces a call to one named function. Leave it unset to let the model decide.
  • A reasoning model spends max_tokens on thinking too. See Reasoning.

Other wire formats#

POST /v1/responses takes function tools and function_call_output. POST /v1/messages uses Anthropic tool_use blocks. See API Compatibility.

Gate tool calls with a fast model#

A coding agent can ask Laya before it runs a tool. System One has a Claude Code hook that asks before a destructive command runs.

NextReasoning