> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://www.respan.ai/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://www.respan.ai/docs/_mcp/server.

# LlamaIndex (gateway)

> Set up LlamaIndex with the Respan gateway.

Route LlamaIndex LLM and embedding calls through the Respan gateway to use 1000+ models from different providers. Only your Respan API key is needed. No separate provider key is required when the provider is configured in Respan.

## Setup

#### Install packages

```bash
pip install llama-index llama-index-llms-openai llama-index-embeddings-openai
```

#### Set environment variables

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
```

#### Point LlamaIndex to the Respan gateway

```python
import os
from llama_index.core import Document, Settings, SummaryIndex
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI

respan_api_key = os.environ["RESPAN_API_KEY"]
respan_base_url = "https://api.respan.ai/api"

Settings.llm = OpenAI(
    api_key=respan_api_key,
    api_base=respan_base_url,
    model="gpt-5-mini",
)
Settings.embed_model = OpenAIEmbedding(
    api_key=respan_api_key,
    api_base=respan_base_url,
    model="text-embedding-3-small",
)

index = SummaryIndex.from_documents([
    Document(text="The Respan gateway routes LlamaIndex calls to hosted models.")
])
response = index.as_query_engine().query("What does the gateway do?")
print(response)
```

## Switch models

Change the `model` parameter to use another OpenAI model through the same gateway-backed endpoint.

```python
Settings.llm = OpenAI(
    api_key=respan_api_key,
    api_base=respan_base_url,
    model="gpt-5.5",
)
```

> **Note**
>
> `OpenAI` is LlamaIndex's OpenAI-compatible LLM adapter. This page avoids showing Claude or Gemini inside that OpenAI-named adapter; use the Respan API or OpenAI SDK gateway pages for provider-neutral Claude and Gemini examples.

See [Respan params & metadata](/docs/documentation/features/gateway/respan-params) for the full list.