Skip to main content

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.

Observability

Instrument your code with OpenTelemetry to capture traces, logs, and metrics for every LLM call, agent step, and tool use.

AI Gateway

Overview

LlamaIndex is a powerful framework for building RAG (Retrieval-Augmented Generation) applications with LLMs. By connecting LlamaIndex to Toqan Router’s AI Gateway, you transform experimental RAG applications into production-ready systems with enterprise-grade capabilities.

Key Benefits

Toqan Router’s AI Gateway enhances your LlamaIndex applications with:

Complete Observability

Track document indexing, retrieval performance, and query processing with detailed traces

Built-in Reliability

Automatic fallbacks, retries, and load balancing for production resilience

Cost Optimization

Real-time cost tracking and spend management across all your AI operations

Multi-Provider Access

Access 500+ LLMs and 30+ providers through a single, unified integration

Prerequisites

Before integrating LlamaIndex with Toqan Router, ensure you have:
  • A Toqan Router account and API Key
  • Python 3.8 or higher
  • LlamaIndex installed in your project
To setup your API key, see API keys & Endpoints.

Installation

Install LlamaIndex and required dependencies:

Configuration

Configure LlamaIndex to use Toqan Router’s AI Gateway with the OpenAILike class:
Python
api_base: https://router.toqan.ai/eu/v3/router

Basic RAG Example

Here’s a complete example of building a RAG application with LlamaIndex through Toqan Router:
Python

Model Selection

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

Streaming Responses

LlamaIndex supports streaming with Toqan Router:
Python

Observability

Getting Started

Integrate LlamaIndex with Toqan Router’s observability to gain comprehensive insights into document indexing, retrieval performance, query processing, and LLM interactions using OpenTelemetry.

Prerequisites

Before you begin, ensure you have:
  • A Toqan Router account and API Key
  • LlamaIndex installed in your project
  • Python 3.8+
  • OpenAI API key (or other LLM provider credentials)

Install Dependencies

Configure Toqan Router

Set up your environment variables to connect to Toqan Router’s OpenTelemetry collector: Unix/Linux/macOS:
Windows (PowerShell):
Using .env file:

Integration Example

We’ll be using OpenInference as TracerProvider with LlamaIndex
Python

View Traces

View your traces in the AI Studio in the Traces tab.
Visit your AI Studio to view real-time analytics and traces.