LangChain Together
raw JSON → 0.4.0 verified Fri May 01 auth: no python
An integration package connecting Together AI's API with LangChain. Provides chat models and embeddings. Current version 0.4.0, requires Python >=3.10, <4.0. Release cadence is irregular; latest releases include security patches and MCP server features.
pip install langchain-together Common errors
error ModuleNotFoundError: No module named 'langchain_together' ↓
cause Package not installed or wrong import path (e.g., from langchain.llms import Together).
fix
Install with 'pip install langchain-together' and import as 'from langchain_together import ChatTogether'.
error InvalidRequestError: 'model' is not a valid parameter ↓
cause Passing the model name as a keyword argument 'model' when it should be passed as positional or via model_kwargs.
fix
Use the correct parameter name: ChatTogether(model='mistralai/Mixtral-8x7B-Instruct-v0.1') or ChatTogether(model_kwargs={'model': '...'}) – check the latest API.
error AuthenticationError: 401 Unauthorized ↓
cause API key missing or incorrect.
fix
Set the TOGETHER_API_KEY environment variable or pass the key via the 'together_api_key' parameter.
error TypeError: __init__() got an unexpected keyword argument 'together_api_key' ↓
cause Using an older version of langchain-together that expected the parameter name 'api_key' instead of 'together_api_key'.
fix
Upgrade to latest version: pip install --upgrade langchain-together
Warnings
breaking Version 0.2.0 introduced a new package structure. If you were using the old langchain_together from community, imports must be updated to 'from langchain_together import ...' instead of 'from langchain.llms import Together' ↓
fix Change imports to the new package: from langchain_together import ChatTogether
deprecated The 'model' parameter used to accept model IDs like 'togethercomputer/llama-2-70b-chat'. These legacy IDs are deprecated in favor of Together AI's new model format (e.g., 'mistralai/Mixtral-8x7B-Instruct-v0.1'). ↓
fix Use the new model naming convention as documented by Together AI.
gotcha The environment variable for the API key is 'TOGETHER_API_KEY', not 'TOGETHER_AI_KEY' or 'TOGETHER_AI_API_KEY'. ↓
fix Set the correct environment variable or pass directly via 'together_api_key' parameter.
gotcha ChatTogether does not support all models available via Together AI's API. Some models may require additional parameters like 'temperature' or 'max_tokens' which are not passed through by default. ↓
fix Check LangChain documentation for supported models and pass extra kwargs if needed.
Imports
- ChatTogether wrong
from langchain_together.chat import ChatTogethercorrectfrom langchain_together import ChatTogether - TogetherEmbeddings wrong
from langchain_together.embeddings import TogetherEmbeddingscorrectfrom langchain_together import TogetherEmbeddings
Quickstart
import os
from langchain_together import ChatTogether
chat = ChatTogether(
together_api_key=os.environ.get("TOGETHER_API_KEY", ""),
model="mistralai/Mixtral-8x7B-Instruct-v0.1"
)
response = chat.invoke("Hello, how are you?")
print(response.content)