> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-opensw-1781706951-9d0138e.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ChatTogether integration

> Integrate with the ChatTogether chat model using LangChain Python.

This page will help you get started with Together AI [chat models](/oss/python/langchain/models). For detailed documentation of all `ChatTogether` features and configurations, head to the [API reference](https://reference.langchain.com/python/langchain-together/chat_models/ChatTogether).

[Together AI](https://www.together.ai/) offers an API to query [50+ leading open-source models](https://docs.together.ai/docs/chat-models)

## Overview

### Integration details

| Class                                                                                                | Package                                                                           | Serializable | [JS support](https://js.langchain.com/docs/integrations/chat/togetherai) |                                              Downloads                                              |                                              Version                                             |
| :--------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------- | :----------: | :----------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------: |
| [`ChatTogether`](https://reference.langchain.com/python/langchain-together/chat_models/ChatTogether) | [`langchain-together`](https://reference.langchain.com/python/langchain-together) |     beta     |                                     ✅                                    | ![PyPI - Downloads](https://img.shields.io/pypi/dm/langchain-together?style=flat-square\&label=%20) | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-together?style=flat-square\&label=%20) |

### Model features

| [Tool calling](/oss/python/langchain/tools) | [Structured output](/oss/python/langchain/structured-output) | [Image input](/oss/python/langchain/messages#multimodal) | Audio input | Video input | [Token-level streaming](/oss/python/langchain/streaming#llm-tokens) | Native async | [Token usage](/oss/python/langchain/models#token-usage) | [Logprobs](/oss/python/langchain/models#log-probabilities) |
| :-----------------------------------------: | :----------------------------------------------------------: | :------------------------------------------------------: | :---------: | :---------: | :-----------------------------------------------------------------: | :----------: | :-----------------------------------------------------: | :--------------------------------------------------------: |
|                      ✅                      |                               ✅                              |                             ✅                            |      ✅      |      ✅      |                                  ✅                                  |       ❌      |                            ✅                            |                              ✅                             |

## Setup

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

### Credentials

Head to [this page](https://api.together.ai) to sign up to Together and generate an API key. Once you've done this, set the TOGETHER\_API\_KEY environment variable:

```python theme={null}
import getpass
import os

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

To enable automated tracing of your model calls, set your [LangSmith](/langsmith/observability) API key:

```python theme={null}
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"
```

### Installation

The LangChain Together integration is included in the `langchain-together` package:

```python theme={null}
pip install -qU langchain-together
```

## Instantiation

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

```python theme={null}
from langchain_together import ChatTogether

llm = ChatTogether(
    model="meta-llama/Llama-3-70b-chat-hf",
    temperature=0,
    max_tokens=None,
    timeout=None,
    max_retries=2,
    # other params...
)
```

## Invocation

```python theme={null}
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={null}
AIMessage(content="J'adore la programmation.", response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 35, 'total_tokens': 44}, 'model_name': 'meta-llama/Llama-3-70b-chat-hf', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-eabcbe33-cdd8-45b8-ab0b-f90b6e7dfad8-0', usage_metadata={'input_tokens': 35, 'output_tokens': 9, 'total_tokens': 44})
```

```python theme={null}
print(ai_msg.content)
```

```text theme={null}
J'adore la programmation.
```

***

## API reference

For detailed documentation of all `ChatTogether` features and configurations, head to the [API reference](https://reference.langchain.com/python/langchain-together/chat_models/ChatTogether)

***

<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/together.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
