{"id":76,"library":"together-ai","title":"Together AI Python SDK","description":"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.","status":"active","version":"1.4.1","language":"python","source_language":"en","source_url":"https://docs.together.ai/docs/openai-api-compatibility","tags":["together","llm","open-source","llama","inference","openai-compatible","fine-tuning"],"install":[{"cmd":"pip install together","lang":"bash","label":"pip (v1 stable)"},{"cmd":"uv add together","lang":"bash","label":"uv"},{"cmd":"pip install --pre --upgrade together","lang":"bash","label":"pip (v2 RC — not GA)"}],"dependencies":[{"reason":"v1 was a full rewrite in April 2024. Pre-v1 code is entirely broken.","package":"together>=1.0.0","optional":false},{"reason":"Optional — can use OpenAI client with Together base_url instead of native SDK.","package":"openai","optional":true}],"imports":[{"note":"Pre-v1 had a completely different import structure. v1+ uses top-level from together import Together.","wrong":"from together.api import Together","symbol":"Together","correct":"from together import Together"},{"note":"Async client. Same interface as Together, use with await.","symbol":"AsyncTogether","correct":"from together import AsyncTogether"},{"note":"Together is fully OpenAI-compatible. Using the OpenAI client with base_url override is a valid and common pattern — no native SDK needed.","symbol":"OpenAI client (alternative)","correct":"openai.OpenAI(api_key=os.environ['TOGETHER_API_KEY'], base_url='https://api.together.xyz/v1')"}],"quickstart":{"code":"import os\nfrom together import Together\n\nclient = Together(api_key=os.environ['TOGETHER_API_KEY'])\n\nresponse = client.chat.completions.create(\n    model='meta-llama/Llama-3.3-70B-Instruct-Turbo',\n    messages=[{'role': 'user', 'content': 'Hello'}]\n)\nprint(response.choices[0].message.content)","lang":"python","description":"Minimal chat completion using native Together SDK"},"warnings":[{"fix":"pip install --upgrade together and rewrite using from together import Together pattern","message":"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.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Use pip install together (no --pre flag) for stable v1. Monitor GitHub for GA announcement.","message":"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.","severity":"breaking","affected_versions":"2.0.0rc*"},{"fix":"Update exception handlers to catch specific v2 error types when migrating to v2.","message":"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.","severity":"breaking","affected_versions":"v1 → v2 migration"},{"fix":"Check the Python SDK Migration Guide for API-by-API before/after examples before upgrading.","message":"Files, Batches, Endpoints, Evals, and Code Interpreter APIs have updated method names and response shapes in v2. Not drop-in compatible.","severity":"breaking","affected_versions":"v1 → v2 migration"},{"fix":"Always verify current model IDs at https://api.together.xyz/models — they change as models are added/removed.","message":"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.","severity":"gotcha","affected_versions":"all"},{"fix":"If already using OpenAI SDK, just swap base_url and api_key. No native Together SDK needed for basic chat/completions/embeddings.","message":"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.","severity":"gotcha","affected_versions":"all"},{"fix":"Set TOGETHER_API_KEY env var. Together() reads it automatically — no need to pass api_key= explicitly.","message":"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.","severity":"gotcha","affected_versions":"all v1+"}],"env_vars":null,"last_verified":"2026-05-12T07:29:21.968Z","next_check":"2026-03-28T00:00:00.000Z","problems":[{"fix":"Install the package using pip: `pip install together-ai`. The correct import is `import together`.","cause":"The Python package `together-ai` has not been installed, or the import statement uses an incorrect module name.","error":"ModuleNotFoundError: No module named 'together'"},{"fix":"Ensure the `TOGETHER_API_KEY` environment variable is set or pass the API key directly when instantiating the client: `client = together.Together(api_key='YOUR_API_KEY')`.","cause":"The Together AI API key is either not provided to the client constructor, not set as an environment variable (`TOGETHER_API_KEY`), or the provided key is invalid.","error":"together.TogetherError: API key is missing or invalid."},{"fix":"Instantiate the client and then use `client.completions.create` or `client.chat.completions.create`: `client = together.Together(); response = client.completions.create(...)`.","cause":"The user is attempting to access static `Completion` methods (pre-v1 API) on an instantiated `together.Together` client object (v1.0+ API), which is incorrect.","error":"AttributeError: 'Together' object has no attribute 'Completion'"},{"fix":"Pass the Together AI API key explicitly to the OpenAI client constructor: `from openai import OpenAI; client = OpenAI(base_url='https://api.together.xyz/v1', api_key=os.environ.get('TOGETHER_API_KEY'))`.","cause":"When using the `openai` client with Together AI's `base_url`, the `openai` library expects the API key to be explicitly passed or the `OPENAI_API_KEY` environment variable to be set, not `TOGETHER_API_KEY`.","error":"openai.AuthenticationError: No API key provided. You can set your API key in code ... or via the OPENAI_API_KEY environment variable."},{"fix":"Use `client.chat.completions.create(model='...', messages=[{'role': 'user', 'content': 'Hello'}])` for chat models, and `client.completions.create(model='...', prompt='Hello, world!')` for completion models.","cause":"The user is trying to pass `messages` (for chat models) to the `together.completions.create` endpoint, which expects a `prompt`.","error":"TypeError: together.completions.create() got an unexpected keyword argument 'messages'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.04,"mem_mb":18.2,"disk_size":"134.8M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.02,"mem_mb":18.2,"disk_size":"134.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.79,"mem_mb":18.2,"disk_size":"205M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.81,"mem_mb":18.2,"disk_size":"205M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.43,"mem_mb":20,"disk_size":"145.6M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.45,"mem_mb":20,"disk_size":"145.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.19,"mem_mb":20,"disk_size":"216M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.19,"mem_mb":20,"disk_size":"216M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.49,"mem_mb":19.8,"disk_size":"135.9M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.49,"mem_mb":19.8,"disk_size":"135.7M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.44,"mem_mb":19.8,"disk_size":"206M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.48,"mem_mb":19.8,"disk_size":"206M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.36,"mem_mb":20.8,"disk_size":"132.5M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.38,"mem_mb":20.8,"disk_size":"132.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.36,"mem_mb":20.8,"disk_size":"205M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.38,"mem_mb":20.8,"disk_size":"205M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.03,"mem_mb":22.2,"disk_size":"130.8M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.01,"mem_mb":22.2,"disk_size":"130.6M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.93,"mem_mb":22.2,"disk_size":"202M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.92,"mem_mb":22.2,"disk_size":"202M"}]},"quickstart_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}