Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@
"v3/integrations/openai-sdk-typescript",
"v3/integrations/langchain",
"v3/integrations/pydantic-ai",
"v3/integrations/aisuite"
"v3/integrations/aisuite",
"v3/integrations/haystack"
]
},
{
Expand Down
1 change: 1 addition & 0 deletions integration-logo/haystack-icondoc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
170 changes: 170 additions & 0 deletions v3/integrations/haystack.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
---
title: "Haystack"
icon: "/integration-logo/haystack-icondoc.svg"
description: "Use Eden AI with Haystack (deepset) to build LLM and RAG pipelines on 500+ AI models through one EU-hosted API key."

Check warning on line 4 in v3/integrations/haystack.mdx

View check run for this annotation

Mintlify / Mintlify Validation (edenai) - vale-spellcheck

v3/integrations/haystack.mdx#L4

Did you really mean 'deepset'?
---

import { TechArticleSchema } from "/snippets/TechArticleSchema.mdx";

<TechArticleSchema
title={"Haystack"}
description={"Use Eden AI with Haystack (deepset) to build LLM and RAG pipelines on 500+ AI models through one EU-hosted API key."}

Check warning on line 11 in v3/integrations/haystack.mdx

View check run for this annotation

Mintlify / Mintlify Validation (edenai) - vale-spellcheck

v3/integrations/haystack.mdx#L11

Did you really mean 'deepset'?
path="v3/integrations/haystack"
articleSection="AI Frameworks"
about={"LLM Framework Integration"}
proficiencyLevel="Intermediate"
keywords={["Eden AI", "AI API", "Haystack", "deepset", "RAG", "Python"]}
datePublished="2026-07-21T00:00:00Z"
dateModified="2026-07-21T00:00:00Z"
/>

Use Eden AI with Haystack (deepset) to build LLM and RAG pipelines on 500+ AI models through one EU-hosted API key.

## 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 500+ more behind one key, with EU-based, GDPR-aligned inference.

Check warning on line 25 in v3/integrations/haystack.mdx

View check run for this annotation

Mintlify / Mintlify Validation (edenai) - vale-spellcheck

v3/integrations/haystack.mdx#L25

Did you really mean 'deepset's'?

The integration provides three components:

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

Models use Eden AI's `provider/model` naming convention, for example `anthropic/claude-sonnet-4-5` or `mistral/mistral-large-latest`.

## Installation

<CodeGroup>
```bash pip
pip install edenai-haystack
```

```bash uv
uv add edenai-haystack
```
</CodeGroup>

## Quick Start

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

<CodeGroup>
```bash .env
EDENAI_API_KEY=your_api_key_here

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use standard token placeholder.

Both snippets use your_api_key_here, but the coding guidelines require distinguishing token types by using api_token (for production) or sandbox_api_token (for testing) in examples without real provider calls. Please update the placeholder to api_token to maintain consistency across the documentation.

  • v3/integrations/haystack.mdx#L53-L53: replace your_api_key_here with api_token
  • v3/integrations/haystack.mdx#L161-L161: replace your_api_key_here with api_token
📍 Affects 1 file
  • v3/integrations/haystack.mdx#L53-L53 (this comment)
  • v3/integrations/haystack.mdx#L161-L161
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@v3/integrations/haystack.mdx` at line 53, Replace the EDENAI_API_KEY
placeholder your_api_key_here with api_token at both affected sites in
v3/integrations/haystack.mdx: lines 53-53 and 161-161, preserving the
surrounding snippets.

Source: Coding guidelines

```

{/* skip-test */}
```python Python
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?")])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use keyword arguments for run() calls.

Haystack 2.x components enforce or strongly expect keyword arguments for their .run() methods. Passing positional arguments will result in a TypeError at runtime, causing these code examples to fail when users copy and paste them. Update these calls to explicitly use kwargs.

  • v3/integrations/haystack.mdx#L63-L63: change generator.run([...]) to generator.run(messages=[...])
  • v3/integrations/haystack.mdx#L88-L88: change generator.run(messages) to generator.run(messages=messages)
  • v3/integrations/haystack.mdx#L107-L107: change generator.run([...]) to generator.run(messages=[...])
  • v3/integrations/haystack.mdx#L131-L131: change doc_embedder.run(documents) to doc_embedder.run(documents=documents)
  • v3/integrations/haystack.mdx#L136-L136: change text_embedder.run("What is Eden AI?") to text_embedder.run(text="What is Eden AI?")
📍 Affects 1 file
  • v3/integrations/haystack.mdx#L63-L63 (this comment)
  • v3/integrations/haystack.mdx#L88-L88
  • v3/integrations/haystack.mdx#L107-L107
  • v3/integrations/haystack.mdx#L131-L131
  • v3/integrations/haystack.mdx#L136-L136
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@v3/integrations/haystack.mdx` at line 63, Update all Haystack 2.x run calls
in v3/integrations/haystack.mdx: lines 63-63 and 107-107 must pass messages=...,
line 88-88 must pass messages=messages, line 131-131 must pass
documents=documents, and line 136-136 must pass text=....

print(response["replies"][0].text)
```
</CodeGroup>

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

## Switching models

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

<CodeGroup>
{/* skip-test */}
```python Python
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-4o-mini",
"anthropic/claude-sonnet-4-5",
"mistral/mistral-large-latest",
]:
generator = EdenAIChatGenerator(model=model)
print(model, "->", generator.run(messages)["replies"][0].text)
```
</CodeGroup>

## Streaming

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

<CodeGroup>
{/* skip-test */}
```python Python
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.")])
```
</CodeGroup>

## Embeddings and RAG

Use `EdenAITextEmbedder` to embed a query and `EdenAIDocumentEmbedder` to embed documents, so you can build a fully sovereign RAG stack (retrieval and generation) on EU-hosted models:

<CodeGroup>
{/* skip-test */}
```python Python
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"])
```
</CodeGroup>

## Available Models

Use the `provider/model` format for any Eden AI model:

**Chat**
- `openai/gpt-4o-mini`
- `anthropic/claude-sonnet-4-5`
- `mistral/mistral-large-latest`
- `google/gemini-2.5-flash`

**Embeddings**
- `openai/text-embedding-3-small`
- `mistral/mistral-embed`

Browse the full list in the [Eden AI models catalog](https://www.edenai.co/models).

## Environment Variables

<CodeGroup>
```bash .env
EDENAI_API_KEY=your_api_key_here
```
</CodeGroup>

## Next Steps

- [Chat Completions](/v3/llms/chat-completions) - Core LLM endpoint
- [List LLM Models](/v3/llms/listing-models) - Browse available providers and models
- [aisuite](/v3/integrations/aisuite) - Another unified LLM interface
- [LangChain](/v3/integrations/langchain) - Build LLM apps with LangChain
Loading