Registry / llm-agents / together

together

JSON →
library2.32.0pypypi✓ verified 25d ago

The Together Python library (v2.x) provides convenient access to the Together AI REST API for Python 3.9+ applications. It offers strongly-typed request parameters and response fields, with both synchronous and asynchronous clients powered by httpx. This modern SDK is generated from the OpenAPI specification using Stainless, ensuring a 1:1 mapping to the API and rapid feature delivery. Version 1.x is now in maintenance mode, with all new development focused on v2.x.

pip install together
INSTALL
IMPORT
SIG · TOGETHER
T
together
llm-agentspythonv2.32.0
Install
6.3s avg
Import
1165ms
Disk
59MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.32.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.224s · 57.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 6.3s · import 1.106s · 57MB
59MB installed
● package 59MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Together
from together import Together
AsyncTogether
from together import AsyncTogether

Demonstrates how to initialize the synchronous client and make a basic chat completion request using an environment variable for the API key.

import os from together import Together # Ensure TOGETHER_API_KEY is set in your environment variables # e.g., export TOGETHER_API_KEY="your_api_key_here" client = Together( api_key=os.environ.get("TOGETHER_API_KEY", "") ) try: chat_completion = client.chat.completions.create( messages=[ {"role": "user", "content": "Say this is a test!"} ], model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo", ) print(chat_completion.choices[0].message.content) except Exception as e: print(f"An error occurred: {e}") print("Please ensure TOGETHER_API_KEY is set and valid, and you have access to the specified model.")
Debug
Known issues
breakingThe Together Python SDK v2.0 (released December 2025) introduced significant breaking changes from v1.x. Key areas affected include constructor parameters (e.g., `supplied_headers` changed to `default_headers`), error handling class internals and exceptions, mandatory keyword arguments for all API calls (no positional parameters), and changes to many response type names in `together.types.*`.
fix
Refer to the official Python SDK Migration Guide for detailed API-by-API notes and code snippets. Update all API calls to use keyword arguments and adjust error handling and type imports accordingly.
affects: >=2.0.0 (from v1.x)
gotchaAPI calls in v2.x and later strictly require all parameters to be passed as keyword arguments. Positional arguments are no longer supported. Attempting to use positional arguments will result in runtime errors.
fix
Always use `param=value` syntax for all arguments when calling methods such as `client.chat.completions.create()`.
affects: >=2.0.0
gotchaFor streaming responses (e.g., chat completions), the default `create` method eagerly reads the full response. To stream tokens incrementally as they are generated by the model, you must explicitly use the `.with_streaming_response` method within a context manager.
fix
Wrap streaming calls with `with client.chat.completions.with_streaming_response(...) as stream_response:` and then iterate over `stream_response.iter_bytes()`, `iter_text()`, or `iter_lines()` for efficient token handling.
affects: >=2.0.0
gotchaThe library extensively uses Pydantic for type validation and data modeling. If your project integrates `together-py` with other Python libraries (e.g., LangChain, FastAPI) that have differing or strict Pydantic v1 or v2 dependencies, you might encounter compatibility issues. Pydantic v2 is a major rewrite and not fully backward compatible with v1.
fix
Ensure all libraries in your project are compatible with a single Pydantic version (preferably v2). If conflicts are unavoidable, consider using tools like `pydantic-compat` or isolating environments, though direct compatibility is ideal. `together-py` v2 is designed for Pydantic v2 environments.
affects: All versions (potential conflict with other libraries)
Errors
Common errors & fixes
AttributeError: module 'together' has no attribute 'ChatCompletion'
Users are attempting to use the Together v1 client syntax or OpenAI library syntax directly on the `together` module instead of instantiating the v2 client.
fix
Instantiate the `together.Together()` client and then use its methods like `client.chat.completions.create`.
```python
import together

client = together.Together()
chat_completion = client.chat.completions.create(
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello world"}
    ],
    model="mistralai/Mixtral-8x7B-Instruct-v0.1"
)
print(chat_completion.choices[0].message.content)
```
together.error.AuthenticationError: Incorrect API key provided
The `TOGETHER_API_KEY` environment variable is either not set, contains an invalid key, or the key has expired or lacks necessary permissions.
fix
Ensure your Together AI API key is correctly set as an environment variable (recommended) or passed directly to the `Together` client constructor.
```python
import together
import os

# Option 1: Set environment variable (e.g., in your shell: export TOGETHER_API_KEY="your_key")
# client = together.Together()

# Option 2: Pass directly
client = together.Together(api_key="YOUR_API_KEY")
```
together.error.BadRequestError: Invalid request: model '...' not found.
The specified model name in the API call is incorrect, misspelled, or the model is not available for your account or region.
fix
Verify the exact model name from the Together AI model list (e.g., on their dashboard) and ensure it is correctly passed in the `model` parameter of your request.
```python
import together

client = together.Together()
chat_completion = client.chat.completions.create(
    messages=[
        {"role": "user", "content": "Hello"}
    ],
    model="mistralai/Mixtral-8x7B-Instruct-v0.1" # Example correct model name
)
```
ModuleNotFoundError: No module named 'together'
The `together` Python library has not been installed in the current Python environment.
fix
Install the library using pip.
```bash
pip install together
```
Upgrade
Version history
2.32.0latest on PyPI · released Aug 26, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.9 or higher for v2.x of the library.
aiohttpoptionalOptional dependency for improved concurrency performance when using the `AsyncTogether` client. Install with `pip install 'together[aiohttp]'`.
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
together — pip install together · libregistry