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

# Haystack

> 在 Haystack OpenAIChatGenerator 中使用 TokenLab

## 概覽

Haystack 的 `OpenAIChatGenerator` 透過 `api_base_url` 支援自訂的 OpenAI 相容部署。將其指向 TokenLab 並提供 TokenLab API key 即可使用。

<Note>
  **類型**: RAG 與 pipeline 框架

  **主要路徑**: OpenAI 相容 Chat Completions

  **支援信心**: 支援 OpenAI 相容路徑
</Note>

## 環境設定

```bash theme={null}
export TOKENLAB_API_KEY="sk-your-tokenlab-key"
```

## Generator

```python theme={null}
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.utils import Secret

generator = OpenAIChatGenerator(
    api_key=Secret.from_env_var("TOKENLAB_API_KEY"),
    api_base_url="https://api.tokenlab.sh/v1",
    model="claude-sonnet-5",
)

response = generator.run(
    messages=[ChatMessage.from_user("Summarize this document in one sentence.")]
)
```

## 端點注意事項

請針對 Haystack chat generator pipelines 使用此路徑。若您的 pipeline 使用 TokenLab embeddings，請將對應的 Haystack embedding 元件設定為 TokenLab 的 `/v1` base URL。
