> ## 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.

# Haystack

> Give a Haystack agent Octen search APIs and Extract.

For AI agents: [docs.octen.ai/integrations/haystack.md](https://docs.octen.ai/integrations/haystack.md)

Each tool wraps a [Python SDK](https://docs.octen.ai/integrations/python-sdk.md) method.

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

> [card] [Python SDK](https://docs.octen.ai/integrations/python-sdk.md)
>
> The `octen` package.

## Install

Requires Python 3.11+.

```bash theme={null}
pip install haystack-ai octen
```

## Quick Start

Set your Octen and OpenAI API keys:

```bash theme={null}
export OCTEN_API_KEY="your-api-key"
export OPENAI_API_KEY="your-openai-api-key"
```

Run an agent that answers with Octen Web Search:

```python theme={null}
from typing import Annotated

from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.tools import tool
from octen import Octen

octen = Octen()  # reads OCTEN_API_KEY


@tool
def web_search(query: Annotated[str, "The search query"]) -> list[dict]:
    """Search the live web and return ranked results with titles, URLs, and highlights."""
    return octen.search.search(query=query, count=5).results


agent = Agent(
    chat_generator=OpenAIChatGenerator(model="gpt-5.4"),
    tools=[web_search],
    system_prompt="Answer with current information from the web and cite the URLs you used.",
)

result = agent.run(messages=[ChatMessage.from_user("What is the latest stable release of Python?")])
print(result["last_message"].text)
```

## Add an Extract Tool

Let the agent read full pages from the URLs it finds, with [Extract](https://docs.octen.ai/capabilities/extract.md). Replace everything from `agent = Agent(` to the end of the Quick Start program with this code:

```python theme={null}
@tool
def extract(urls: Annotated[list[str], "The URLs to read, up to 20"]) -> list[dict]:
    """Read up to 20 web pages and return their content as Markdown."""
    return octen.extract.extract(urls=urls).results


agent = Agent(
    chat_generator=OpenAIChatGenerator(model="gpt-5.4"),
    tools=[web_search, extract],
    system_prompt="Answer with current information from the web and cite the URLs you used.",
)

result = agent.run(messages=[ChatMessage.from_user("What are the three biggest changes in Python 3.15? Read the official What's New page before you answer.")])
print(result["last_message"].text)
```

## Add More Search Tools

Let the agent 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).

Replace everything from `agent = Agent(` to the end of the program from [Add an Extract Tool](#add-an-extract-tool) with this code. Each tool returns the response `data`, with the same fields as the API reference:

```python theme={null}
@tool
def web_search_premier(query: Annotated[str, "The search query"]) -> dict:
    """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."""
    return octen.search.search_premier(query=query).data


@tool
def broad_search(query: Annotated[str, "The search query"]) -> dict:
    """Split a broad or comparative question into sub-queries, search them all, and return results grouped per sub-query."""
    return octen.search.broad_search(query=query).data


@tool
def news_search(query: Annotated[str, "The search query"]) -> dict:
    """Search recent news and return ranked articles plus storylines that group related coverage."""
    return octen.search.news_search(query=query).data


@tool
def business_search(query: Annotated[str, "The search query"]) -> dict:
    """Look up companies and people and return their profile cards plus ranked sources."""
    return octen.search.business_search(query=query).data


@tool
def pulse_search(query: Annotated[str, "The search query"]) -> dict:
    """Predict the URLs a query points to, such as official sites, docs, or help pages, and return their titles and URLs."""
    return octen.search.pulse_search(query=query).data


@tool
def place_search(query: Annotated[str, "The search query"]) -> dict:
    """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."""
    return octen.place_search.search(query=query).data


@tool
def image_search(query: Annotated[str, "The search query"]) -> dict:
    """Search the web for images and return image URLs with their source pages."""
    return octen.image_search.search(query=query).data


@tool
def design_search(query: Annotated[str, "The search query"]) -> dict:
    """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."""
    return octen.design_search.search(query=query).data


agent = Agent(
    chat_generator=OpenAIChatGenerator(model="gpt-5.4"),
    tools=[web_search, extract, web_search_premier, broad_search, news_search, business_search, pulse_search, place_search, image_search, design_search],
    system_prompt="Answer with current information from the web and cite the URLs you used.",
)

result = agent.run(messages=[ChatMessage.from_user("Compare Stripe and Adyen, including their latest news.")])
print(result["last_message"].text)
```

## Use Auto Search

Skip the tool loop and let Octen run the searches server-side with [Auto Search](https://docs.octen.ai/capabilities/auto-search.md). Point the chat generator at the Octen base URL and enable the built-in `octen_search` tool. Your Octen API key is the only key you need:

```python theme={null}
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.utils import Secret

generator = OpenAIChatGenerator(
    api_key=Secret.from_env_var("OCTEN_API_KEY"),
    api_base_url="https://api.octen.ai/v1",
    model="openai/gpt-5.4",
    generation_kwargs={"extra_body": {"tools": [{"type": "octen_search"}]}},
)
result = generator.run(messages=[ChatMessage.from_user("What happened in AI this week?")])
print(result["replies"][0].text)
```

***

Last modified on November 24, 2026


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