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

# TogetherAI integration

> Integrate with the TogetherAI LLM using LangChain JavaScript.

<Warning>
  **You are currently on a page documenting the use of Together AI models as text completion models. Many popular models available on Together AI are [chat completion models](/oss/javascript/langchain/models).**

  You may be looking for [this page instead](/oss/javascript/integrations/chat/togetherai/).
</Warning>

[Together AI](https://www.together.ai/) offers an API to query [50+ leading open-source models](https://docs.together.ai/docs/inference-models) in a couple lines of code.

This will help you get started with Together AI text completion models (LLMs) using LangChain. For detailed documentation on `TogetherAI` features and configuration options, please refer to the [API reference](https://reference.langchain.com/javascript/langchain-together-ai/TogetherAI).

## Overview

### Integration details

| Class                                                                                       | Package                                                                          | Local | Serializable | [PY support](https://python.langchain.com/docs/integrations/llms/together/) |                                                Downloads                                               |                                               Version                                               |
| :------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------- | :---: | :----------: | :-------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------: |
| [`TogetherAI`](https://reference.langchain.com/javascript/langchain-together-ai/TogetherAI) | [`@langchain/together-ai`](https://www.npmjs.com/package/@langchain/together-ai) |   ❌   |       ✅      |                                      ✅                                      | ![NPM - Downloads](https://img.shields.io/npm/dm/@langchain/together-ai?style=flat-square\&label=%20&) | ![NPM - Version](https://img.shields.io/npm/v/@langchain/together-ai?style=flat-square\&label=%20&) |

## Setup

To access the legacy `TogetherAI` completions class, create a Together account, [get an API key](https://api.together.xyz/), and install the `@langchain/together-ai` integration package. For chat and instruct models, prefer [`ChatTogetherAI`](/oss/javascript/integrations/chat/togetherai).

### Credentials

Head to [api.together.ai](https://api.together.ai/) to sign up to Together AI and generate an API key. Set the `TOGETHER_AI_API_KEY` environment variable:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export TOGETHER_AI_API_KEY="your-api-key"
```

If you want to get automated tracing of your model calls you can also set your [LangSmith](/langsmith/observability) API key by uncommenting below:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"
```

### Installation

The LangChain TogetherAI integration lives in the `@langchain/together-ai` package:

<CodeGroup>
  ```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  npm install @langchain/together-ai @langchain/core
  ```

  ```bash yarn theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  yarn add @langchain/together-ai @langchain/core
  ```

  ```bash pnpm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pnpm add @langchain/together-ai @langchain/core
  ```
</CodeGroup>

## Instantiation

Instantiate the completions model:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { TogetherAI } from "@langchain/together-ai";

const llm = new TogetherAI({
  model: "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
  maxTokens: 256,
});
```

## Invocation

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const inputText = "Together is an AI company that "

const completion = await llm.invoke(inputText)
completion
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
 offers a range of AI-powered solutions to help businesses and organizations improve their customer service, sales, and marketing efforts. Their platform uses natural language processing (NLP) and machine learning algorithms to analyze customer interactions and provide insights and recommendations to help businesses improve their customer experience.
Together's solutions include:
1. Customer Service: Together's customer service solution uses AI to analyze customer interactions and provide insights and recommendations to help businesses improve their customer experience. This includes analyzing customer feedback, sentiment analysis, and predictive analytics to identify areas for improvement.
2. Sales: Together's sales solution uses AI to analyze customer interactions and provide insights and recommendations to help businesses improve their sales efforts. This includes analyzing customer behavior, sentiment analysis, and predictive analytics to identify opportunities for upselling and cross-selling.
3. Marketing: Together's marketing solution uses AI to analyze customer interactions and provide insights and recommendations to help businesses improve their marketing efforts. This includes analyzing customer behavior, sentiment analysis, and predictive analytics to identify areas for improvement.
Together's platform is designed to be easy to use and integrates with a range of popular CRM and marketing automation tools. Their solutions are available as a cloud-based subscription service, making it easy for businesses to get started with AI-powered customer service, sales, and marketing.
Overall,
```

***

## API reference

For detailed documentation of all `TogetherAI` features and configurations head to the [API reference](https://reference.langchain.com/javascript/langchain-together-ai/TogetherAI).

***

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