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

# LangChain 集成

> 在 LangChain 中通过 OpenAI 兼容格式使用 AGICTO API

LangChain 可以通过 OpenAI 兼容客户端连接 AGICTO API。你只需要配置 API Key、Base URL 和模型名。

## 安装

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

## Node.js 示例

```js theme={null}
import { ChatOpenAI } from "@langchain/openai";

const model = new ChatOpenAI({
  apiKey: process.env.AGICTO_API_KEY,
  model: process.env.AGICTO_CHAT_MODEL,
  configuration: {
    baseURL: "https://api.agicto.cn/v1/"
  }
});

const result = await model.invoke("请用一句话介绍 AGICTO API。");
console.log(result.content);
```

## Python 示例

```bash theme={null}
pip install langchain-openai
```

```python theme={null}
import os
from langchain_openai import ChatOpenAI

model = ChatOpenAI(
    api_key=os.environ["AGICTO_API_KEY"],
    base_url="https://api.agicto.cn/v1/",
    model=os.environ["AGICTO_CHAT_MODEL"],
)

result = model.invoke("请用一句话介绍 AGICTO API。")
print(result.content)
```

## 配置项

| 字段       | 值                           |
| -------- | --------------------------- |
| API Key  | AGICTO API Key              |
| Base URL | `https://api.agicto.cn/v1/` |
| Model    | 从模型列表复制的模型名                 |

<Card title="模型广场" icon="boxes-stacked" href="/guides/models">
  查看模型类型、厂商和模型名使用方式。
</Card>
