Overview
We’re excited to announce the release of Python v2, an upgrade to the Together AI Python SDK. This guide will help you migrate from the legacy (v1) SDK to the new version. Why Migrate? The new SDK offers several advantages:- Modern Architecture: Built with Stainless OpenAPI generator for consistency and reliability
- Better Type Safety: Comprehensive typing for better IDE support and fewer runtime errors
- Broader Python Support: Python 3.8+ (vs 3.10+ in legacy)
- Modern HTTP Client: Uses
httpxinstead ofrequests - Faster Performance: ~20ms faster per request on internal benchmarks
- uv Support: Compatible with uv, the fast Python package installer -
uv add together
Feature Parity Matrix
Use this table to quickly assess the migration effort for your specific use case: Legend: ✅ No changes | ⚠️ Minor changes needed | 🆕 New capability| Feature | Legacy SDK | New SDK | Migration Notes |
|---|---|---|---|
| Chat Completions | ✅ | ✅ | No changes required |
| Text Completions | ✅ | ✅ | No changes required |
| Vision | ✅ | ✅ | No changes required |
| Function Calling | ✅ | ✅ | No changes required |
| Structured Decoding (JSON Mode) | ✅ | ✅ | No changes required |
| Embeddings | ✅ | ✅ | No changes required |
| Image Generation | ✅ | ✅ | No changes required |
| Video Generation | ✅ | ✅ | No changes required |
| Streaming | ✅ | ✅ | No changes required |
| Async Support | ✅ | ✅ | No changes required |
| Models List | ✅ | ✅ | No changes required |
| Rerank | ✅ | ✅ | No changes required |
| Audio Speech (TTS) | ✅ | ✅ | ⚠️ Voice listing: dict access → attribute access |
| Audio Transcription | ✅ | ✅ | ⚠️ File paths → file objects with context manager |
| Audio Translation | ✅ | ✅ | ⚠️ File paths → file objects with context manager |
| Fine-tuning | ✅ | ✅ | ⚠️ list_checkpoints response changed, download → content |
| File Upload/Download | ✅ | ✅ | ⚠️ retrieve_content → content, no longer writes to disk |
| Batches | ✅ | ✅ | ⚠️ Method names simplified, response shape changed |
| Endpoints | ✅ | ✅ | ⚠️ get → retrieve, response shapes changed |
| Evaluations | ✅ | ✅ | ⚠️ Namespace changed to evals, parameters restructured |
| Code Interpreter | ✅ | ✅ | ⚠️ run → execute |
| Raw Response Access | ❌ | ✅ | 🆕 New feature |
Installation & Setup
1. Install the New SDKSome constructor parameters have changed. See Constructor Parameters for details.
Global Breaking Changes
Constructor Parameters
The client constructor has been updated with renamed and new parameters:supplied_headers→default_headers(renamed)- New optional parameters:
default_query,http_client
Keyword-Only Arguments
All API method arguments must now be passed as keyword arguments. Positional arguments are no longer supported.Optional Parameters
The new SDK usesNOT_GIVEN instead of None for omitted optional parameters. In most cases, you can simply omit the parameter entirely:
Extra Parameters
The legacy**kwargs pattern has been replaced with explicit parameters for passing additional data:
Response Type Names
Most API methods have renamed response type definitions. If you’re importing response types for type hints, you’ll need to update your imports:CLI Commands Removed
The following CLI commands have been removed in the new SDK:together chat.completionstogether completionstogether images generate
APIs with No Changes Required
The following APIs work identically in both SDKs. No code changes are needed: Chat CompletionsAPIs with Changes Required
Batches Method names have been simplified, and the response structure has changed slightly.create_batch()→create()get_batch()→retrieve()list_batches()→list()cancel_batch()→cancel()file_id→input_file_idcreate()returns full response; access.jobfor the job object
get()→retrieve()min_replicasandmax_replicasare now nested insideautoscalingparameterlist()response changed: previously returned array directly, now returns object with.data
retrieve_content()→content()- No longer writes to disk automatically; returns binary data for you to handle
- Response is now an object with
.datacontaining the list of checkpoints - Checkpoint properties renamed:
type→checkpoint_type,timestamp→created_at nameno longer exists; construct fromft_idandstep
download()→content()with streaming response- No longer writes to disk automatically
run()→execute()- Output access:
result.output→result.data.outputs[0].data - New
sessions.list()method for session management
- File paths (strings) → file objects opened with
open(file, "rb") - Use context managers (
with open(...) as f:) for proper resource cleanup
- Voice properties:
voice['name']→voice.name(dict access → attribute access)
- Namespace:
client.evaluation→client.evals - Parameters restructured with typed parameter objects
retrieve()andstatus()no longer use named arguments
New SDK-Only Features
Raw Response Access Access raw HTTP responses for debugging:Error Handling Migration
The exception hierarchy has been completely restructured with a new, more granular set of HTTP status-specific exceptions. Update your error handling code accordingly:| Legacy SDK Exception | New SDK Exception | Notes |
|---|---|---|
TogetherException | TogetherError | Base exception renamed |
AuthenticationError | AuthenticationError | HTTP 401 |
RateLimitError | RateLimitError | HTTP 429 |
Timeout | APITimeoutError | Renamed |
APIConnectionError | APIConnectionError | Unchanged |
ResponseError | APIStatusError | Base class for HTTP errors |
InvalidRequestError | BadRequestError | HTTP 400 |
ServiceUnavailableError | InternalServerError | HTTP 500+ |
JSONError | APIResponseValidationError | Response parsing errors |
InstanceError | APIStatusError | Use base class or specific status error |
APIError | APIError | Base for all API errors |
FileTypeError | FileTypeError | Still exists (different module) |
DownloadError | DownloadError | Still exists (different module) |
PermissionDeniedError(403)NotFoundError(404)ConflictError(409)UnprocessableEntityError(422)
Troubleshooting
Import Errors Problem:None for optional parameters; omit them instead:
Best Practices
Type Safety Take advantage of improved typing:httpx. Configure it as needed:
Getting Help
If you encounter issues during migration:- To see the code check the new SDK repo
- Review the API Reference which has updated v2 code examples
- Report issues and discuss changes on discord
- Contact support for additional help