Together AI Python SDK
Official Python SDK for Together AI platform. OpenAI-compatible API for running 100+ open-source models. Has gone through two full rewrites: pre-v1 (2023) → v1.0 (April 2024) → v2.0 RC (2025, not yet GA on PyPI). Can also be used via OpenAI client with base_url override.
Warnings
- breaking Pre-v1 SDK (before April 2024) is completely incompatible. Different imports, different client structure, different method names. All pre-v1 tutorials and code are broken.
- breaking v2.0 RC is available via pip install --pre but is NOT GA. Breaking changes still possible during RC period. Do not use in production.
- breaking v2.0 redesigns error handling entirely. TogetherException replaced with TogetherError hierarchy (APIStatusError, BadRequestError, AuthenticationError, RateLimitError). Error handling code from v1 will not catch v2 errors.
- breaking Files, Batches, Endpoints, Evals, and Code Interpreter APIs have updated method names and response shapes in v2. Not drop-in compatible.
- gotcha Model IDs use provider/model-name format (e.g. meta-llama/Llama-3.3-70B-Instruct-Turbo). LLMs frequently hallucinate incorrect Together-specific model ID formats.
- gotcha Together API is OpenAI-compatible. You can use the OpenAI Python client with base_url='https://api.together.xyz/v1' and TOGETHER_API_KEY. This is not a hack — it's documented and supported.
- gotcha The legacy together package (pre-v1) used TOGETHER_API_KEY but stored it differently. v1+ reads TOGETHER_API_KEY env var automatically via Together() with no argument.
Install
-
pip install together -
uv add together -
pip install --pre --upgrade together
Imports
- Together
from together import Together
- AsyncTogether
from together import AsyncTogether
- OpenAI client (alternative)
openai.OpenAI(api_key=os.environ['TOGETHER_API_KEY'], base_url='https://api.together.xyz/v1')
Quickstart
import os
from together import Together
client = Together(api_key=os.environ['TOGETHER_API_KEY'])
response = client.chat.completions.create(
model='meta-llama/Llama-3.3-70B-Instruct-Turbo',
messages=[{'role': 'user', 'content': 'Hello'}]
)
print(response.choices[0].message.content)