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

# LlamaIndex

> Use Nordlys with LlamaIndex for Mixture of Models in RAG applications and AI agents

## Get Your Nordlys API Key

[Sign up here](https://nordlyslabs.com/api-platform/orgs) to create an account and generate your API key.

## Quick Setup

### Installation

<CodeGroup>
  ```bash pip theme={null}
  pip install llama-index-llms-openai llama-index-embeddings-openai
  ```

  ```bash uv theme={null}
  uv add llama-index-llms-openai llama-index-embeddings-openai
  ```

  ```bash poetry theme={null}
  poetry add llama-index-llms-openai llama-index-embeddings-openai
  ```

  ```bash npm theme={null}
  npm install llamaindex @llamaindex/openai
  ```

  ```bash yarn theme={null}
  yarn add llamaindex @llamaindex/openai
  ```

  ```bash pnpm theme={null}
  pnpm add llamaindex @llamaindex/openai
  ```

  ```bash bun theme={null}
  bun add llamaindex @llamaindex/openai
  ```
</CodeGroup>

### Basic Integration

```python theme={null}
import os
from llama_index.llms.openai import OpenAI
from llama_index.core import Settings

# Set your Nordlys API key
os.environ["OPENAI_API_KEY"] = os.environ["NORDLYS_API_KEY"]

# Initialize OpenAI client with Nordlys endpoint
llm = OpenAI(
    model="nordlys/hypernova",
    api_base="https://api.nordlyslabs.com/v1",
    api_key=os.environ["NORDLYS_API_KEY"],
)

# Set as global model
Settings.llm = llm

# Use with simple queries
response = llm.complete("What is retrieval-augmented generation?")
print(response)
```

## RAG Example

```python theme={null}
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

# Load documents
documents = SimpleDirectoryReader("data").load_data()

# Create index
index = VectorStoreIndex.from_documents(documents)

# Query with Mixture of Models
query_engine = index.as_query_engine()
response = query_engine.query("What are the benefits of RAG?")
print(response)
```

## Key Benefits

* **Mixture of Models** - Mixture of Models activation for queries and agents
* **RAG-optimized** - Nordlys activates specialists per prompt
* **Cost optimization** - 30-70% cost reduction across RAG pipelines
* **Agent support** - Mixture of Models activation for function-calling agents

## Next Steps

<CardGroup cols={2}>
  <Card title="More Examples" href="/examples/basic-chat" icon="code">
    See complete working examples with LlamaIndex
  </Card>

  <Card title="API Reference" href="/api-reference/chat-completions" icon="book">
    Explore all available options and parameters
  </Card>
</CardGroup>
