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

# LlamaIndex Agents integration

> Connect LlamaIndex Agents to Toqan Router's AI Gateway for complete observability, built-in reliability, and access to 500+ LLMs across 30+ providers.

> [card] [AI Gateway](#ai-gateway)
>
> Route your LLM calls through the AI Gateway with a single base URL change. Zero vendor lock-in: always run on the best model at the lowest cost for your use case.

## AI Gateway

### Overview

LlamaIndex Agents is an agentic framework built on top of LlamaIndex that enables LLMs to reason, use tools, and execute multi-step workflows. By connecting LlamaIndex Agents to Toqan Router's AI Gateway, you get production-ready agents with enterprise-grade capabilities without changing your existing code.

### Key Benefits

Toqan Router's AI Gateway enhances your LlamaIndex Agents with:

> [card] Complete Observability
>
> Track every agent step, tool use, and reasoning trace with detailed analytics

> [card] Built-in Reliability
>
> Automatic fallbacks, retries, and load balancing for production resilience

> [card] Cost Optimization
>
> Real-time cost tracking and spend management across all your AI operations

> [card] Multi-Provider Access
>
> Access 500+ LLMs and 30+ providers through a single, unified integration

### Prerequisites

Before integrating LlamaIndex Agents with Toqan Router, ensure you have:

* A Toqan Router account and API Key
* Python 3.8 or higher
* LlamaIndex installed in your project

> [!NOTE]
>
> To setup your API key, see API keys & Endpoints.

### Installation

Install LlamaIndex and required dependencies:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
pip install llama-index llama-index-llms-openai-like
```

### Configuration

Configure LlamaIndex Agents to use Toqan Router's AI Gateway with the `OpenAILike` class:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from llama_index.llms.openai_like import OpenAILike
import os

# Configure OpenAI-compatible LLM with Toqan Router AI Gateway
llm = OpenAILike(
    model="openai/gpt-5.6-sol",
    api_key=os.getenv("TOQAN_API_KEY"),
    api_base="https://router.toqan.ai/eu/v3/router",
    is_chat_model=True,
)
```

> **api\_base**: `https://router.toqan.ai/eu/v3/router`

### Basic Agent Example

Here's a complete example using `ReActAgent` with a simple tool:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import asyncio
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.tools import FunctionTool
from llama_index.llms.openai_like import OpenAILike
import os

# Configure LLM with Toqan Router AI Gateway
llm = OpenAILike(
    model="openai/gpt-5.6-sol",
    api_key=os.getenv("TOQAN_API_KEY"),
    api_base="https://router.toqan.ai/eu/v3/router",
    is_chat_model=True,
)

# Define a tool
def get_weather(location: str) -> str:
    """Get the current weather for a location."""
    return f"The weather in {location} is sunny and 72°F"

# Create agent
agent = ReActAgent(
    tools=[FunctionTool.from_defaults(get_weather)],
    llm=llm,
)

async def main():
    response = await agent.run("What's the weather in San Francisco?")
    print(response)

asyncio.run(main())
```

### Agent with Multiple Tools

Build agents with multiple tools for complex reasoning:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import asyncio
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.tools import FunctionTool
from llama_index.llms.openai_like import OpenAILike
import os

llm = OpenAILike(
    model="openai/gpt-5.6-sol",
    api_key=os.getenv("TOQAN_API_KEY"),
    api_base="https://router.toqan.ai/eu/v3/router",
    is_chat_model=True,
)

def add(a: int, b: int) -> int:
    """Add two integers."""
    return a + b

def multiply(a: int, b: int) -> int:
    """Multiply two integers."""
    return a * b

def get_company_info(company: str) -> str:
    """Get basic information about a company."""
    companies = {
        "openai": "OpenAI is an AI research company founded in 2015.",
        "anthropic": "Anthropic is an AI safety company founded in 2021.",
    }
    return companies.get(company.lower(), f"No information found for {company}")

agent = ReActAgent(
    tools=[
        FunctionTool.from_defaults(add),
        FunctionTool.from_defaults(multiply),
        FunctionTool.from_defaults(get_company_info),
    ],
    llm=llm,
    system_prompt="You are a helpful assistant with access to math and company information tools.",
)

async def main():
    response = await agent.run("What is 15 * 4, and tell me about Anthropic?")
    print(response)

asyncio.run(main())
```

### Model Selection

With Toqan Router, you can use any supported model from 30+ providers:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import asyncio
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.tools import FunctionTool
from llama_index.llms.openai_like import OpenAILike
import os

def get_time(timezone: str) -> str:
    """Get the current time in a timezone."""
    return f"The current time in {timezone} is 14:30"

# Use Claude
claude_llm = OpenAILike(
    model="anthropic/claude-sonnet-5",
    api_key=os.getenv("TOQAN_API_KEY"),
    api_base="https://router.toqan.ai/eu/v3/router",
    is_chat_model=True,
)

# Use Gemini
gemini_llm = OpenAILike(
    model="google/gemini-2.5-pro",
    api_key=os.getenv("TOQAN_API_KEY"),
    api_base="https://router.toqan.ai/eu/v3/router",
    is_chat_model=True,
)

agent = ReActAgent(
    tools=[FunctionTool.from_defaults(get_time)],
    llm=claude_llm,
)

async def main():
    response = await agent.run("What time is it in Tokyo?")
    print(response)

asyncio.run(main())
```


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