Skip to main content

Together AI

Together AI offers an API to query 50+ leading open-source models in a couple lines of code.

This example goes over how to use LangChain to interact with Together AI models.


%pip install --upgrade langchain-together


To use Together AI, you'll need an API key which you can find here: This can be passed in as an init param together_api_key or set as environment variable TOGETHER_API_KEY.


# Querying chat models with Together AI

from langchain_together import ChatTogether

# choose from our 50+ models here:
chat = ChatTogether(
# together_api_key="YOUR_API_KEY",

# stream the response back from the model
for m in"Tell me fun things to do in NYC"):
print(m.content, end="", flush=True)

# if you don't want to do streaming, you can use the invoke method
# chat.invoke("Tell me fun things to do in NYC")

API Reference:

# Querying code and language models with Together AI

from langchain_together import Together

llm = Together(
# together_api_key="..."

print(llm.invoke("def bubble_sort(): "))

API Reference:

Help us out by providing feedback on this documentation page: