Skip to main content

ChatFireworks integration

还没翻译译自英文(docs.langchain.com)本页 26 段都还没译

This doc helps you get started with Fireworks AI chat models. For a list of all models served by Fireworks see the Fireworks docs.

Tip

API Reference

For detailed documentation of all features and configuration options, head to the ChatFireworks API reference.

Overview

Integration details

ClassPackageSerializableJS/TS SupportDownloadsVersion
ChatFireworkslangchain-fireworksbeta✅ (npm)PyPI - DownloadsPyPI - Version

Model features

Tool callingStructured outputImage inputAudio inputVideo inputToken-level streamingNative asyncToken usageLogprobs
✅✅✅❌❌✅✅✅✅

Note

Image input requires a vision-capable model (e.g. Kimi K3). Not all models served by Fireworks support multimodal inputs.

Setup

To access Fireworks models you'll need to create a Fireworks account, get an API key, and install the langchain-fireworks integration package.

Credentials

Head to fireworks.ai to sign up to Fireworks and generate an API key. Once you've done this set the FIREWORKS_API_KEY environment variable:

import getpass
import os

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

To enable automated tracing of your model calls, set your LangSmith API key:

os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"

Installation

The LangChain Fireworks integration lives in the langchain-fireworks package:

pip install -qU langchain-fireworks

Instantiation

Now we can instantiate our model object and generate chat completions:

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,
    # other params...
)

Invocation

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
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})
print(ai_msg.content)
J'adore la programmation.

Reasoning effort

Some Fireworks-hosted models support the standard reasoning_effort parameter, which controls the amount of reasoning the model does. ChatFireworks forwards it unchanged as the reasoning_effort request field. Supported values vary by model. It can be set at model construction or per invocation:

from langchain_fireworks import ChatFireworks

model = ChatFireworks(model="accounts/fireworks/models/deepseek-v4-pro")
response = model.invoke(
    "Analyze the trade-offs between microservices and monolithic architectures",
    reasoning_effort="high",
)

Note

reasoning_effort as a standard parameter requires langchain-fireworks>=1.5.2.

Check a model's profile for the effort levels it supports:

model.profile["reasoning_effort_levels"]  # e.g. ['low', 'medium', 'high']

API reference

For detailed documentation of all features and configuration options, head to the ChatFireworks API reference.