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

# LangChain integration guide

LangChain is a software framework for developing applications powered by (large language models) LLMs. This guide walks you through using LangChain to interact with SambaNova models.

<Note>
  View the following resources for more information:

  * [ChatSambaNova document](https://docs.langchain.com/oss/python/integrations/chat/sambanova)
  * [SambaNova-LangChain document](https://docs.langchain.com/oss/python/integrations/providers/sambanova)
  * [LangChain official document](https://docs.langchain.com/oss/python/langchain/overview)
  * [End-to-end code examples using LangChain and SambaNova](https://github.com/sambanova/ai-starter-kit)
  * [SambaNovaEmbeddings document](https://docs.langchain.com/oss/python/integrations/text_embedding/sambanova)
</Note>

Follow the example below to see how you can directly instantiate a ChatSambaNova model from LangChain and prompt it.

## Setup

Do the following to access ChatSambaNova models:

1. Create a [SambaCloud](http://cloud.sambanova.ai/?utm_source=langchain\&utm_medium=external\&utm_campaign=cloud_signup) account and get an API key.
2. Run the command below to install the `langchain-sambanova` integration package.

```
pip install langchain-sambanova
```

## Credentials

Run the commands below to register the API key you received from [cloud.sambanova.ai](https://cloud.sambanova.ai/apis) as an environment variable.

```
import os

sambanova_api_key = "your-sambanova-api-key"
os.environ["SAMBANOVA_API_KEY"] = sambanova_api_key
```

## Instantiation

Now you can instantiate a ChatSambaNova model object and generate chat completions, as shown in the example below. The example below uses Meta’s Llama 3.3 70B.

```
from langchain_sambanova import ChatSambaNova

llm = ChatSambaNova(
    model="Meta-Llama-3.3-70B-Instruct",
    max_tokens=1024,
    temperature=0.7,
    top_p=0.01,
)
```

## Invocation

You can invoke the model using the command below.

```
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)
print(ai_msg.content)
```

You should see an output similar to the one below.

```
J'adore la programmation.
```

## Chaining

You can [chain](https://python.langchain.com/docs/how_to/sequence/) the model with a prompt template, as shown in the example below.

```
from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate(
    [
        (
            "system",
            "You are a helpful assistant that translates {input_language} "
            "to {output_language}.",
        ),
        ("human", "{input}"),
    ]
)

chain = prompt | llm
response = chain.invoke(
    {
        "input_language": "English",
        "output_language": "German",
        "input": "I love programming.",
    }
)
print(response.content)
```

You should see an output similar to the one below.

```
Ich liebe das Programmieren.
```
