> ## Documentation Index
> Fetch the complete documentation index at: https://docs.octen.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic Tool Calling

> Register Octen search APIs and Extract as tools in the Anthropic Messages API.

For AI agents: [docs.octen.ai/integrations/anthropic-tool-calling.md](https://docs.octen.ai/integrations/anthropic-tool-calling.md)

Claude decides when to search, your code runs the query on Octen [Web Search](https://docs.octen.ai/capabilities/web-search.md), and Claude answers from the results.

> [card] [Get API Key](https://octen.ai/platform/api-keys)
>
> Create a key from the API Platform.

> [card] [Web Search API Reference](https://docs.octen.ai/api-reference/search.md)
>
> Full request/response schema.

## Install

```bash theme={null}
pip install anthropic octen
```

## Quick Start

Set your Octen and Anthropic API keys:

```bash theme={null}
export OCTEN_API_KEY="your-api-key"
export ANTHROPIC_API_KEY="your-anthropic-api-key"
```

Run a tool-calling loop with Octen Web Search:

```python theme={null}
import json

import anthropic
from octen import Octen

client = anthropic.Anthropic()  # reads ANTHROPIC_API_KEY
octen = Octen()  # reads OCTEN_API_KEY

tools = [
    {
        "name": "web_search",
        "description": "Search the web for real-time information.",
        "input_schema": {
            "type": "object",
            "properties": {
                "query": {"type": "string", "description": "The search query."},
            },
            "required": ["query"],
        },
    },
]


def web_search(query):
    response = octen.search.search(query=query, count=5)
    results = [
        {"title": r.get("title"), "url": r.get("url"), "highlight": r.get("highlight")}
        for r in response.results
    ]
    return json.dumps(results)


functions = {"web_search": web_search}

messages = [{"role": "user", "content": "What happened in AI this week?"}]

while True:
    response = client.messages.create(
        model="claude-sonnet-5-5",
        max_tokens=16000,
        tools=tools,
        messages=messages,
    )
    if response.stop_reason != "tool_use":
        break

    messages.append({"role": "assistant", "content": response.content})
    tool_results = [
        {
            "type": "tool_result",
            "tool_use_id": block.id,
            "content": functions[block.name](**block.input),
        }
        for block in response.content
        if block.type == "tool_use"
    ]
    messages.append({"role": "user", "content": tool_results})

print("".join(block.text for block in response.content if block.type == "text"))
```

Append `response.content` unchanged, thinking blocks included, and send every `tool_result` from one turn back in a single user message.

## Add an Extract Tool

Let Claude read a full page from a URL it finds, with [Extract](https://docs.octen.ai/capabilities/extract.md). Add this code to the Quick Start program, right after `functions = {"web_search": web_search}`:

```python theme={null}
def extract(url):
    response = octen.extract.extract(urls=[url])
    item = response.items[0]
    if item.status != "success":
        return json.dumps({"url": url, "error": item.error_message})
    return json.dumps({"title": item.title, "url": item.url, "content": item.full_content})


tools.append(
    {
        "name": "extract",
        "description": "Read a web page and return its content as markdown.",
        "input_schema": {
            "type": "object",
            "properties": {
                "url": {"type": "string", "description": "The URL of the page to read."},
            },
            "required": ["url"],
        },
    }
)
functions["extract"] = extract
```

## Add More Search Tools

Let Claude also use [Web Search Premier](https://docs.octen.ai/capabilities/web-search-premier.md), [Broad Search](https://docs.octen.ai/capabilities/broad-search.md), [News Search](https://docs.octen.ai/capabilities/news-search.md), [Business Search](https://docs.octen.ai/capabilities/business-search.md), [Pulse Search](https://docs.octen.ai/capabilities/pulse-search.md), [Place Search](https://docs.octen.ai/capabilities/place-search.md), [Image Search](https://docs.octen.ai/capabilities/image-search.md), and [Design Search](https://docs.octen.ai/capabilities/design-search.md).

Add this code to the Quick Start program, right after `functions = {"web_search": web_search}`. Each tool takes a `query` and returns the response `data` as JSON, with the same fields as the API reference:

```python theme={null}
search_tools = {
    "web_search_premier": (octen.search.search_premier, "Search the web more broadly and rank more carefully than web_search, for a specific fact, a niche document, or a named page, and return ranked pages with query-relevant highlights."),
    "broad_search": (octen.search.broad_search, "Split a broad or comparative question into sub-queries, search them all, and return results grouped per sub-query."),
    "news_search": (octen.search.news_search, "Search recent news and return ranked articles plus storylines that group related coverage."),
    "business_search": (octen.search.business_search, "Look up companies and people and return their profile cards plus ranked sources."),
    "pulse_search": (octen.search.pulse_search, "Predict the URLs a query points to, such as official sites, docs, or help pages, and return their titles and URLs."),
    "place_search": (octen.place_search.search, "Find places such as restaurants, shops, or hotels and return place cards with address, opening hours, and rating. Include the city or area in the query."),
    "image_search": (octen.image_search.search, "Search the web for images and return image URLs with their source pages."),
    "design_search": (octen.design_search.search, "Search real web pages, app screens, and slides for design references and return them as images with their design values, such as colors and fonts, plus web results."),
}

for name, (method, description) in search_tools.items():
    tools.append(
        {
            "name": name,
            "description": description,
            "input_schema": {
                "type": "object",
                "properties": {
                    "query": {"type": "string", "description": "The search query."},
                },
                "required": ["query"],
            },
        }
    )
    functions[name] = lambda query, method=method: json.dumps(method(query=query).data)
```

***

Last modified on November 24, 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.