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

# LangChain（Gemini）

> 使用 LangChain 的 ChatGoogleGenerativeAI 接入 PipeLLM 的 Gemini 路由

认证和模型列表请参考 [Gemini 概述](/api-reference/gemini/overview.zh)。

<Note>
  这页是框架集成文档。原始 HTTP 端点说明请看
  [Generate Content](/api-reference/gemini/generate-content.zh)。
</Note>

## 安装

```bash theme={null}
pip install langchain-google-genai
```

## 代码示例

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import os
    from langchain_google_genai import ChatGoogleGenerativeAI

    llm = ChatGoogleGenerativeAI(
      model='gemini-3-flash-preview',
      google_api_key=os.getenv('PIPELLM_API_KEY'),
      transport='rest',
      client_options={'api_endpoint': 'https://api.pipellm.ai'}
    )

    response = llm.invoke([
      ('user', 'Why is the sky blue?')
    ])

    print(response.content)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    import { ChatGoogleGenerativeAI } from '@langchain/google-genai';

    const llm = new ChatGoogleGenerativeAI({
      model: 'gemini-3-flash-preview',
      apiKey: process.env.PIPELLM_API_KEY,
      baseUrl: 'https://api.pipellm.ai'
    });

    const response = await llm.invoke([
      { role: 'user', content: 'Why is the sky blue?' }
    ]);

    console.log(response.content);
    ```
  </Tab>
</Tabs>

## 流式响应

```python theme={null}
import os
from langchain_google_genai import ChatGoogleGenerativeAI

llm = ChatGoogleGenerativeAI(
  model='gemini-3-flash-preview',
  google_api_key=os.getenv('PIPELLM_API_KEY'),
  transport='rest',
  client_options={'api_endpoint': 'https://api.pipellm.ai'},
  streaming=True
)

for chunk in llm.stream('Tell me a story'):
  print(chunk.content, end='', flush=True)
```

## 相关文档

<Columns cols={3}>
  <Card title="Gemini 概述" icon="sparkles" href="/api-reference/gemini/overview.zh">
    查看 Header、模型和原生路由
  </Card>

  <Card title="Generate Content" icon="code" href="/api-reference/gemini/generate-content.zh">
    查看 `POST /v1beta/models/{model}:generateContent` 的端点说明
  </Card>

  <Card title="开发工具总览" icon="terminal" href="/integrations/overview.zh">
    查看 PipeLLM 上的更多工具与框架集成
  </Card>
</Columns>
