> ## Documentation Index
> Fetch the complete documentation index at: https://nvd-54.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ChatFireworks 集成

> 使用 LangChain Python 集成 ChatFireworks 聊天模型。

This doc helps you get started with Fireworks AI [聊天模型](/oss/python/langchain/models). For a list of all models served by Fireworks 请参阅 [Fireworks docs](https://fireworks.ai/models).

<Tip>
  **API 参考**

  有关所有 features and configuration options, 请前往 [`ChatFireworks`](https://reference.langchain.com/python/langchain-fireworks/chat_models/ChatFireworks) API reference.
</Tip>

## 概述

### 集成详情

| 类                                                                                                       | 包                                                                                    | 可序列化 |                             JS/TS Support                            |                                                  下载量                                                 |                                                 版本                                                |
| :------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------------------------------- | :--: | :------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------: |
| [`ChatFireworks`](https://reference.langchain.com/python/langchain-fireworks/chat_models/ChatFireworks) | [`langchain-fireworks`](https://reference.langchain.com/python/langchain-fireworks/) | beta | ✅ [(npm)](https://js.langchain.com/docs/integrations/chat/fireworks) | ![PyPI - Downloads](https://img.shields.io/pypi/dm/langchain-fireworks?style=flat-square\&label=%20) | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-fireworks?style=flat-square\&label=%20) |

### 模型功能

| [Tool calling](/oss/python/langchain/tools) | [Structured output](/oss/python/langchain/structured-output) | [Image input](/oss/python/langchain/messages#multimodal) | 音频输入 | 视频输入 | [Token-level streaming](/oss/python/langchain/streaming/) | 原生异步 | [Token usage](/oss/python/langchain/models#token-usage) | [Logprobs](/oss/python/langchain/models#log-probabilities) |
| :-----------------------------------------: | :----------------------------------------------------------: | :------------------------------------------------------: | :--: | :--: | :-------------------------------------------------------: | :--: | :-----------------------------------------------------: | :--------------------------------------------------------: |
|                      ✅                      |                               ✅                              |                             ❌                            |   ❌  |   ❌  |                             ✅                             |   ✅  |                            ✅                            |                              ✅                             |

## 设置

要访问 Fireworks 模型，您需要创建一个 Fireworks 账户，获取 API 密钥，并安装 `langchain-fireworks` 集成包。

### 凭证

前往 [fireworks.ai](https://app.fireworks.ai/login) 注册 Fireworks 并生成 API 密钥。 完成后设置 FIREWORKS\_API\_KEY 环境变量：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import getpass
import os

if "FIREWORKS_API_KEY" not in os.environ:
    os.environ["FIREWORKS_API_KEY"] = getpass.getpass("Enter your Fireworks API key: ")
```

要启用模型调用的自动追踪，请设置您的 [LangSmith](/langsmith/home) API key:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("请输入您的 LangSmith API 密钥: ")
os.environ["LANGSMITH_TRACING"] = "true"
```

### 安装

LangChain 的 Fireworks 集成位于 `langchain-fireworks` 包中：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU langchain-fireworks
```

## 实例化

现在我们可以实例化模型对象并生成聊天补全：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_fireworks import ChatFireworks

llm = ChatFireworks(
    model="accounts/fireworks/models/kimi-k2-instruct-0905",
    temperature=0,
    max_tokens=None,
    timeout=None,
    max_retries=2,
    # 其他参数...
)
```

## 调用

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
messages = [
    (
        "system",
        "You are a helpful assistant that translates English to French. Translate the user sentence.",
    ),
    ("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
ai_msg
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
AIMessage(content="J'adore la programmation.", additional_kwargs={}, response_metadata={'token_usage': {'prompt_tokens': 31, 'total_tokens': 41, 'completion_tokens': 10}, 'system_fingerprint': '', 'finish_reason': 'stop', 'logprobs': None, 'model_provider': 'fireworks', 'model_name': 'accounts/fireworks/models/kimi-k2-instruct-0905'}, id='lc_run--a2bdeca3-6394-4c80-97ad-2fc8db9f54bb-0', usage_metadata={'input_tokens': 31, 'output_tokens': 10, 'total_tokens': 41})
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
print(ai_msg.content)
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
J'adore la programmation.
```

## API 参考

有关所有 features and configuration options, 请前往 [`ChatFireworks`](https://reference.langchain.com/python/langchain-fireworks/chat_models/ChatFireworks) API reference.

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/chat/fireworks.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
