LangChain

LangChain, the most widely adopted of these libraries, provides developers with powerful tools and patterns for managing complex prompts and conversational state.

Prerequisites

  1. Sign up for an account at Featherless

  2. Subscribe to a plan and get your API key from API Keys

Setup

First, let's import the required libraries and set up our API key.

!pip install langchain langchain-featherless-ai

Creating a LangChain Chat Model

Now we'll create a ChatOpenAI instance configured to use Featherless's API. We'll set up the model to use Meta's Llama 3 8B Instruct model through Featherless's API endpoint.

LangChain Chat Model
from langchain_featherless_ai import ChatFeatherlessAi
import os
# Set your API key
FEATHERLESSAI_API_KEY="your featherless api key" # Replace with actual API key
llm = ChatFeatherlessAi(
    api_key=f'{FEATHERLESSAI_API_KEY}',
    base_url="https://api.featherless.ai/v1",
)
# Setting up a Conversation
messages = [
    (
        "system",
        "You are a helpful assistant that translates English to French. Translate the user sentence.",
    ),
    (
        "human",
        "I love programming."
    ),
]
# Processing the response
ai_msg = llm.invoke(messages)

We’ve created a simple conversation that asks the model to translate English to French. Now we can send our messages to the model and get the translation. The invoke() method handles the API call and returns the model’s response.

Resources

Last edited: Jun 16, 2025