# Tool calling

> Define a tool, read the call the model makes, send the result back and stream it, with the OpenAI and Anthropic SDKs against the Hollow model API.

Tools work the way they do in the OpenAI and Anthropic SDKs. The model asks for a tool call, your code runs it, and you send the result back in the next request. Hollow never runs a tool for you.

Only models with Tool calling in the [Models](https://platform.projecthollow.com/docs/models.md) table can use tools. A request to any other model runs without them.

To try a tool without writing code, define it in the Playground under Parameters. The call appears in the conversation, you type the result, and sending it lets the model carry on.

## Define a tool

Send the tool definitions with the request. A tool has a name, a description and a JSON Schema for its input.

**OpenAI-compatible request with a tool**

**curl**

```bash
curl 'https://models.projecthollow.com/v1/chat/completions' \
  -H "Authorization: Bearer $HOLLOW_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "claude-haiku-5-5",
  "messages": [
    {
      "role": "user",
      "content": "What is the weather in Leeds?"
    }
  ],
  "max_tokens": 256,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string"
            }
          },
          "required": [
            "city"
          ]
        }
      }
    }
  ]
}'
```

**Python**

```python
from openai import OpenAI

client = OpenAI(
    api_key="HOLLOW_API_KEY",
    base_url="https://models.projecthollow.com/v1",
)

response = client.chat.completions.create(
    model="claude-haiku-5-5",
    messages=[
        {
            "role": "user",
            "content": "What is the weather in Leeds?",
        },
    ],
    max_tokens=256,
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "description": "Get the current weather for a city.",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "city": {
                            "type": "string",
                        },
                    },
                    "required": [
                        "city",
                    ],
                },
            },
        },
    ],
)
print(response.choices[0].message.content)
```

**TypeScript**

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "HOLLOW_API_KEY",
  baseURL: "https://models.projecthollow.com/v1",
});

const response = await client.chat.completions.create({
  "model": "claude-haiku-5-5",
  "messages": [
    {
      "role": "user",
      "content": "What is the weather in Leeds?"
    }
  ],
  "max_tokens": 256,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string"
            }
          },
          "required": [
            "city"
          ]
        }
      }
    }
  ]
});
console.log(response.choices[0].message.content);
```

**Anthropic-compatible request with a tool**

**curl**

```bash
curl 'https://models.projecthollow.com/v1/messages' \
  -H "Authorization: Bearer $HOLLOW_API_KEY" \
  -H 'anthropic-version: 2023-06-01' \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "claude-haiku-5-5",
  "max_tokens": 256,
  "messages": [
    {
      "role": "user",
      "content": "What is the weather in Leeds?"
    }
  ],
  "tools": [
    {
      "name": "get_weather",
      "description": "Get the current weather for a city.",
      "input_schema": {
        "type": "object",
        "properties": {
          "city": {
            "type": "string"
          }
        },
        "required": [
          "city"
        ]
      }
    }
  ]
}'
```

**Python**

```python
from anthropic import Anthropic

client = Anthropic(
    auth_token="HOLLOW_API_KEY",
    base_url="https://models.projecthollow.com",
)

message = client.messages.create(
    model="claude-haiku-5-5",
    max_tokens=256,
    messages=[
        {
            "role": "user",
            "content": "What is the weather in Leeds?",
        },
    ],
    tools=[
        {
            "name": "get_weather",
            "description": "Get the current weather for a city.",
            "input_schema": {
                "type": "object",
                "properties": {
                    "city": {
                        "type": "string",
                    },
                },
                "required": [
                    "city",
                ],
            },
        },
    ],
)
print(message.content)
```

**TypeScript**

```typescript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  authToken: "HOLLOW_API_KEY",
  baseURL: "https://models.projecthollow.com",
});

const message = await client.messages.create({
  "model": "claude-haiku-5-5",
  "max_tokens": 256,
  "messages": [
    {
      "role": "user",
      "content": "What is the weather in Leeds?"
    }
  ],
  "tools": [
    {
      "name": "get_weather",
      "description": "Get the current weather for a city.",
      "input_schema": {
        "type": "object",
        "properties": {
          "city": {
            "type": "string"
          }
        },
        "required": [
          "city"
        ]
      }
    }
  ]
});
console.log(message.content);
```

The OpenAI-compatible endpoint also accepts the older `functions` list in place of `tools`.

## Read the call

- OpenAI-compatible: `finish_reason` is `tool_calls`, and `message.tool_calls` lists each call with an `id`, a `function.name` and `function.arguments`. The arguments are a JSON string: parse it.
- Anthropic-compatible: `stop_reason` is `tool_use`, and `content` holds a `tool_use` block for each call with an `id`, a `name` and an `input` object.

## Send the result back

1. Run the tool in your code.
2. Add the model's reply to `messages` exactly as you received it.
3. Add the result, tied to the call by its id, and send the request again with the same `tools`.

**Read the call and send the result back**

**OpenAI SDK**

```python
choice = response.choices[0]
if choice.finish_reason == "tool_calls":
    call = choice.message.tool_calls[0]
    arguments = json.loads(call.function.arguments)  # {"city": "Leeds"}
    result = get_weather(**arguments)

messages.append(choice.message)
messages.append({"role": "tool", "tool_call_id": call.id, "content": result})

final = client.chat.completions.create(model="claude-haiku-5-5", messages=messages, tools=tools)
print(final.choices[0].message.content)
```

**Anthropic SDK**

```python
if message.stop_reason == "tool_use":
    call = next(block for block in message.content if block.type == "tool_use")
    result = get_weather(**call.input)  # call.input is {"city": "Leeds"}

messages.append({"role": "assistant", "content": message.content})
messages.append({
    "role": "user",
    "content": [{"type": "tool_result", "tool_use_id": call.id, "content": result}],
})

final = client.messages.create(model="claude-haiku-5-5", max_tokens=256, messages=messages, tools=tools)
print(final.content[0].text)
```

- OpenAI-compatible: the result is a message with the role `tool` and the `tool_call_id` of the call. Its content is text.
- Anthropic-compatible: the result is a `tool_result` block in a user message with the `tool_use_id` of the call. Set `is_error` to `true` when the tool failed.
- A model can ask for several tools in one reply. Send one result for each.

## Stream a tool call

Add `"stream": true` as for any request. Text arrives as it is written. A tool call arrives whole, not in pieces: the name and the complete arguments come together once the model has finished the call.

- OpenAI-compatible: one chunk carries the call in `delta.tool_calls`, with the arguments complete. The last chunk has `finish_reason` set to `tool_calls`.
- Anthropic-compatible: a `tool_use` content block starts, one `input_json_delta` carries the whole input, and `message_delta` ends with `stop_reason` set to `tool_use`.

The streaming parts of both SDKs read these events as they would any others. Build the call from the event, then send the result back as above.
