Skip to main content
LlamaIndex is a data framework for building LLM applications over your own data, including RAG pipelines, query engines, and multi-agent systems. By setting api_base to the gateway URL, all LlamaIndex LLM calls route through Portkey.

Installation

1

Start the gateway

The gateway listens at http://localhost:8787/v1.
2

Install dependencies

Basic setup

Set api_base on the OpenAI LLM class to point at the gateway.

Adding routing configs via headers

Pass gateway configs through default_headers to enable retries, caching, fallbacks, and other features.

Using in a query engine

Once the LLM is configured, pass it to Settings and build any LlamaIndex index or query engine as normal.

Real-world use case: multi-agent system with multiple LLMs

Route different agents to different LLMs through the gateway, with full observability over every request.
When using the hosted gateway, all LlamaIndex requests appear in the Portkey observability dashboard with token counts, latency, and cost — without any additional instrumentation.