---
title: "LlamaIndex (gateway)"
description: "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.

Paste this into your coding agent:

```text
Help me set up the Respan gateway with the LlamaIndex integration.
Follow https://www.respan.ai/docs/integrations/gateway/llama-index.md
```

## Setup

<Steps>
<Step title="Install packages">

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

</Step>

<Step title="Set environment variables">

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

</Step>

<Step title="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://gateway.respan.ai"

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)
```

</Step>
</Steps>

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

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