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

# Use Haystack with Eden AI

> Run Eden AI chat and embedding models in Haystack RAG pipelines with the edenai-haystack package: one API key for 500+ models from many providers.

**Use Haystack with Eden AI**

Run Eden AI chat and embedding models in Haystack RAG pipelines with the edenai-haystack package: one API key for 500+ models from many providers.

Install one package and the Eden AI components drop into any Haystack pipeline, so you can mix chat and embedding models from different providers without changing pipeline code.

## Overview

[Haystack](https://haystack.deepset.ai/) is deepset's open-source Python framework for building production LLM applications, RAG pipelines and agents. **Eden AI ships as an official Haystack integration** (the `edenai-haystack` package), so your pipelines reach models from OpenAI, Anthropic, Google, Mistral and hundreds more behind one key.

The integration provides three components:

* `EdenAIChatGenerator` for chat completion
* `EdenAITextEmbedder` to embed a query string
* `EdenAIDocumentEmbedder` to embed documents for indexing

## Installation

The package requires Python 3.11 or later.

```bash pip theme={null}
pip install edenai-haystack
```

```bash uv theme={null}
uv add edenai-haystack
```

## Quick Start

Set your key, then generate a chat response with the `EdenAIChatGenerator`:

```bash .env theme={null}
EDENAI_API_KEY=your_api_key_here
```

```python Python theme={null}
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.generators.edenai import EdenAIChatGenerator

generator = EdenAIChatGenerator(model="mistral/mistral-large-latest")

response = generator.run([ChatMessage.from_user("What is Eden AI?")])
print(response["replies"][0].text)
```

The generator reads your key from the `EDENAI_API_KEY` environment variable by default.

## Model naming

Models use the `provider/model` format, for example `anthropic/claude-sonnet-latest` for chat and `openai/text-embedding-3-small` for embeddings. See [List LLM Models](https://www.edenai.co/docs/v3/llms/listing-models.md) for the live catalog.

## Switching models

Change providers by changing the `model` string. Every Eden AI chat model is reachable the same way:

```python Python theme={null}
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.generators.edenai import EdenAIChatGenerator

messages = [ChatMessage.from_user("Write a haiku about the sea.")]

for model in [
    "openai/gpt-mini-latest",
    "anthropic/claude-sonnet-latest",
    "mistral/mistral-large-latest",
]:
    generator = EdenAIChatGenerator(model=model)
    print(model, "->", generator.run(messages)["replies"][0].text)
```

## Streaming

Pass a `streaming_callback` to stream tokens as they are generated:

```python Python theme={null}
from haystack.components.generators.utils import print_streaming_chunk
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.generators.edenai import EdenAIChatGenerator

generator = EdenAIChatGenerator(
    model="mistral/mistral-large-latest",
    streaming_callback=print_streaming_chunk,
)
generator.run([ChatMessage.from_user("Count from one to five.")])
```

## Embeddings and RAG

Use `EdenAITextEmbedder` to embed a query and `EdenAIDocumentEmbedder` to embed documents, so you can build a RAG pipeline (retrieval and generation) with one Eden AI key:

```python Python theme={null}
from haystack import Document
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
from haystack_integrations.components.embedders.edenai import (
    EdenAIDocumentEmbedder,
    EdenAITextEmbedder,
)

document_store = InMemoryDocumentStore(embedding_similarity_function="cosine")

# Index documents with their embeddings
documents = [Document(content="Eden AI is a unified API for 500+ AI models.")]
doc_embedder = EdenAIDocumentEmbedder(model="openai/text-embedding-3-small")
document_store.write_documents(doc_embedder.run(documents)["documents"])

# Embed the query and retrieve
text_embedder = EdenAITextEmbedder(model="openai/text-embedding-3-small")
retriever = InMemoryEmbeddingRetriever(document_store=document_store)
query_embedding = text_embedder.run("What is Eden AI?")["embedding"]
print(retriever.run(query_embedding=query_embedding)["documents"])
```

## Environment Variables

`EDENAI_API_KEY` is read by `EdenAIChatGenerator`, `EdenAITextEmbedder` and `EdenAIDocumentEmbedder`, as shown in the Quick Start. To override it, import `Secret` with `from haystack.utils import Secret` and pass `api_key=Secret.from_token("...")` to a component.

## Next Steps

* [Chat Completions](https://www.edenai.co/docs/v3/llms/chat-completions.md) - Core LLM endpoint
* [List LLM Models](https://www.edenai.co/docs/v3/llms/listing-models.md) - Browse available providers and models
* [aisuite](https://www.edenai.co/docs/v3/integrations/aisuite.md) - Another unified LLM interface
* [LangChain](https://www.edenai.co/docs/v3/integrations/langchain.md) - Build LLM apps with LangChain


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.