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

# LlamaIndex

> 了解如何在 LlamaIndex 中使用 OpenAILike LLM 类和 OpenAI-compatible endpoint，接入 siflow endpoint 并构建 RAG 与 agent 应用。

[LlamaIndex](https://github.com/run-llama/llama_index) 是常用的 RAG 和 agents 数据框架。它的 `OpenAILike` LLM 类面向任意 OpenAI-compatible endpoint，因此可以接入 siflow endpoint。

本文默认模型为 `glm-5.2`；完整模型列表和价格请查看 [模型广场](https://console.siflow.cn/model-inference/models)。

## 配置

在 [API 密钥](https://console.siflow.cn/model-inference/api_keys) 页面创建 API Key，并将其导出为环境变量：

```bash theme={null}
export SIFLOW_API_KEY="<Your API Key>"
```

安装 `llama-index-llms-openai-like`，然后创建一个 `OpenAILike` LLM：

```python theme={null}
import os
from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    model="glm-5.2",
    api_base="https://api.siflow.cn/model-api/v1",
    api_key=os.environ["SIFLOW_API_KEY"],
    is_chat_model=True,
)
```

| 字段              | 说明                                                                     |
| --------------- | ---------------------------------------------------------------------- |
| `model`         | 模型 ID，例如 `glm-5.2`                                                     |
| `api_base`      | siflow OpenAI-compatible endpoint：`https://api.siflow.cn/model-api/v1` |
| `api_key`       | 从环境变量读取的 API Key                                                       |
| `is_chat_model` | 设置为 `True`，让 LlamaIndex 使用 chat-completions API                        |

请使用 `OpenAILike`，不要使用 `OpenAI`。普通 `OpenAI` 类会根据 OpenAI 自有模型列表校验 model ID，并拒绝模型 ID。

如果要做 embeddings/RAG，请通过对应的 LlamaIndex embedding integration 添加 embedding 模型，例如 `Qwen/Qwen3-Embedding-8B`。

## 验证

调用模型。如果返回正常回复，即表示连接成功：

```python theme={null}
print(llm.complete("In one short sentence, which model are you?"))
# → I am GLM, a large language model developed by Z.ai.
```
