Skip to main content
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.You may be looking for this page instead.
Together AI offers an API to query 50+ leading open-source 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.

Overview

Integration details

ClassPackageLocalSerializablePY supportDownloadsVersion
TogetherAI@langchain/communityNPM - DownloadsNPM - Version

Setup

To access ChatTogetherAI models you’ll need to create a Together account, get an API key here, and install the @langchain/community integration package.

Credentials

Head to api.together.ai to sign up to TogetherAI and generate an API key. Once you’ve done this set the TOGETHER_AI_API_KEY environment variable:
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 API key by uncommenting below:
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"

Installation

The LangChain TogetherAI integration lives in the @langchain/community package:
import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";
<IntegrationInstallTooltip></IntegrationInstallTooltip>

<Npm2Yarn>
  @langchain/community @langchain/core
</Npm2Yarn>

Instantiation

Now we can instantiate our model object and generate chat completions:
import { TogetherAI } from "@langchain/community/llms/togetherai";

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

Invocation

const inputText = "Together is an AI company that "

const completion = await llm.invoke(inputText)
completion
 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.
I