Skip to main content
This doc helps you get started with Fireworks AI chat models. For a list of all models served by Fireworks see the Fireworks docs.
API ReferenceFor 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

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.

API reference

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