# Tools and function calling

## Server tools

Site6 executes built-in tools when they are included in `tools`. You can also call one directly with **POST `/v1/tools/execute`**.

~~~bash
curl --fail-with-body -sS https://site6.eokgg.win/v1/tools/execute \
  -H "Authorization: Bearer $SITE6_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"name":"calculator","arguments":{"expression":"17 * 3"}}'
~~~

### Built-in tool catalogue

| Tool | Use | Arguments |
| --- | --- | --- |
| `web_search` | Find public sources for a focused query. | query (string), max_results (integer, optional) |
| `fetch_url` | Read text from a public HTTPS page. | url (string) |
| `calculator` | Evaluate arithmetic with parentheses, powers, constants pi/e and common mathematical functions. | expression (string) |
| `time` | Get the current date and time in an IANA time zone. | timezone (string, optional) |
| `clock` | Get the current date, day of the week and time. The default time zone is UTC. | timezone (string, optional) |
| `weather` | Get current weather at latitude and longitude using Open-Meteo. | latitude (number), longitude (number) |
| `convert_units` | Convert length, mass, time, temperature, volume or speed units. | value (number), from (string), to (string) |
| `random_number` | Generate a random integer in an inclusive range. | minimum (integer), maximum (integer) |
| `generate_uuid` | Generate a new UUID version 4. | None |
| `sha256` | Calculate the SHA-256 digest of UTF-8 text. | text (string) |

Call **GET `/v1/tools`** for the complete JSON schemas.

### Use a built-in tool in chat

~~~json
{
  "model": "deepseek-v4.1-flash-1017",
  "messages": [{"role": "user", "content": "Use the calculator to multiply 17 by 3."}],
  "tools": [{"type": "calculator"}],
  "tool_choice": "required",
  "max_tokens": 256
}
~~~

For a current fact, use `{"type":"web_search"}`. With automatic tool choice, a self-contained chat can skip search. Search tool results identify the sources and whether they came from upstream or Site6. Responses accepts a dedicated web search selector when the lookup is required.

## Client functions

Declare a function as an object schema. Site6 returns a matching call for your application to execute.

~~~json
{
  "model": "deepseek-v4.1-flash-1017",
  "messages": [{"role": "user", "content": "Find the shipping status for order DEMO-42."}],
  "tools": [{
    "type": "function",
    "function": {
      "name": "lookup_order",
      "description": "Read the status of a sample order.",
      "parameters": {
        "type": "object",
        "properties": {"order_id": {"type": "string"}},
        "required": ["order_id"],
        "additionalProperties": false
      }
    }
  }],
  "tool_choice": "auto"
}
~~~

Append the returned assistant message including `tool_calls`. Then append one `tool` message per call. The example below shows the two new messages after your original user message.

~~~json
[
  {
    "role": "assistant",
    "content": null,
    "tool_calls": [{
      "id": "call_example",
      "type": "function",
      "function": {"name": "lookup_order", "arguments": "{\"order_id\":\"DEMO-42\"}"}
    }]
  },
  {
    "role": "tool",
    "tool_call_id": "call_example",
    "content": "{\"status\":\"Shipped\"}"
  }
]
~~~

Use the actual ID in the response. Resend the complete Chat message array, available tool definitions and any custom instructions. [Responses continuations](/responses/#return-a-tool-result) represent the same exchange with `function_call_output`.

## Tool options and limits

`tool_choice` accepts `auto`, `none`, `required` or a named function. Set `parallel_tool_calls: false` for a single call. A request accepts up to 512 tool definitions and up to 32 parallel calls. Schema and argument sizes also count towards the request and context limits.

Site6 validates tool calls and reports the actual router in `tool_router_model` when relevant. If a server tool succeeded and the final generation failed, the error can include `tool_results`. Keep those results before retrying to avoid repeating completed actions.

## Build a Responses tool loop

This Python example uses a small in-memory example store. It sends each tool result with the original `call_id`, keeps completed results and continues until the model returns an answer. Set `SITE6_API_KEY` and optionally `SITE6_MODEL` before running it.

~~~python
import json
import os
from urllib.request import Request, urlopen

endpoint = "https://site6.eokgg.win/v1/responses"
model = os.getenv("SITE6_MODEL", "deepseek-v4.1-flash-1017")
orders = {"DEMO-42": "shipped"}
tool = {
    "type": "function",
    "name": "lookup_order",
    "description": "Read the shipping status of a demo order.",
    "parameters": {
        "type": "object",
        "properties": {"order_id": {"type": "string"}},
        "required": ["order_id"],
        "additionalProperties": False,
    },
}

previous = None
completed = {}
next_input = "Look up order DEMO-42 and tell me whether it has shipped."

for _ in range(5):
    body = {
        "model": model,
        "input": next_input,
        "instructions": "Use lookup_order when an order status is requested.",
        "tools": [tool],
        "max_output_tokens": 256,
        "store": True,
    }
    if previous:
        body["previous_response_id"] = previous
    request = Request(
        endpoint,
        data=json.dumps(body).encode("utf-8"),
        headers={
            "Authorization": "Bearer " + os.environ["SITE6_API_KEY"],
            "Content-Type": "application/json",
        },
        method="POST",
    )
    with urlopen(request, timeout=120) as http:
        response = json.load(http)

    if response["status"] != "completed":
        raise RuntimeError(response.get("incomplete_details") or response["status"])
    calls = [item for item in response["output"] if item["type"] == "function_call"]
    if not calls:
        text = [
            part["text"]
            for item in response["output"] if item["type"] == "message"
            for part in item["content"] if part["type"] == "output_text"
        ]
        print("".join(text))
        break

    next_input = []
    for call in calls:
        call_id = call["call_id"]
        if call_id not in completed:
            arguments = json.loads(call["arguments"])
            order_id = arguments.get("order_id")
            if call["name"] == "lookup_order" and isinstance(order_id, str):
                completed[call_id] = {"status": orders.get(order_id, "unknown")}
            else:
                completed[call_id] = {"error": "Unsupported tool or arguments"}
        next_input.append({
            "type": "function_call_output",
            "call_id": call_id,
            "output": json.dumps(completed[call_id]),
        })
    previous = response["id"]
else:
    raise RuntimeError("Reached the tool round limit")
~~~

For a tool that changes external state, validate the arguments and permissions first. Store the result against a stable operation ID as well as the call ID before sending the result back. This lets your application retry a failed continuation without repeating the action. For stateless requests, [send the call and its result with the original input](/responses/#return-a-tool-result).
