Together AI runs dozens of open models (DeepSeek, Qwen, Kimi, GLM, MiniMax and more) behind one pay-per-token API. You can call it with its own Python SDK or with the OpenAI SDK by changing one URL.
This guide walks you from zero to working code in Python. It covers keys, current model IDs, streaming, tools, JSON output, images, dedicated endpoints, prices and the errors you are most likely to hit.
- Install:
pip install together(version 3.6.0, released 1 Dec 2026, needs Python 3.10+). - Key: set
TOGETHER_API_KEY. You must buy at least $15 of credits before you can create a key. There is no free trial. - OpenAI SDK: use
base_url="https://api.together.ai/v1"and a Together model ID such asMiniMaxAI/MiniMax-M3.1-Flash. - Cheap picks: MiniMax M3.1 Flash ($0.15 in / $0.60 out per 1M tokens), Qwen3.5 9B ($0.17 / $0.25), GLM-5.3 Flash ($0.15 / $0.50).
- Serverless vs dedicated: serverless bills per token; dedicated endpoints bill per minute per GPU (H100 at $5.49/hour).
- Rate limits: no fixed published RPM. Together throttles under high demand with 429 or 503, so add exponential backoff.
What the Together AI API Is and When to Use It
Together AI is an inference cloud for open-weight models. You send a chat request, Together runs the model on its GPUs, and you pay for the tokens. The API follows the OpenAI chat completions format, so most existing code moves over with small changes.
It is a good fit when you want:
- Open models without your own GPUs: DeepSeek V4.1, Kimi K3.1 Pro, Qwen4 Max, GLM-5.3 and others, all from one key.
- Low prices: several capable models cost $0.15 per million input tokens.
- A path to dedicated capacity: the same code works on a private dedicated endpoint later.
- Extra modalities: image, video, text-to-speech and speech-to-text models sit on the same platform.
If you want many providers behind one router instead, see our OpenRouter guide. For a wider price view, check the AI API pricing comparison.
Before You Start: Credits and Requirements
Together AI is fully prepaid. According to its billing docs, there is no free trial, and you must buy at least $15 of credits before you can use the playground or create API keys. Later top-ups have a $5 minimum.

You also need:
- Python 3.10 or newer: the
togetherpackage 3.6.0 listsrequires_python >=3.10on PyPI. - A card or US bank account: card credits appear within moments; ACH credits take 1-3 business days.
- A positive balance: if your balance hits zero, API access is suspended until you add credits.
Tip: Turn on auto-recharge in billing settings so a busy app does not stop with a 402 error. Together also added spend alert emails at 50%, 85% and 100% of a monthly amount on 2 December 2026.
Set Up Your Key and the Python SDK
- Create an account. Sign up at api.together.ai.
- Buy credits. Open billing settings, select Add credits in the Credit balance card, and buy at least $15.
- Create a key. Go to your project’s API keys page, select Create key, give it a name and copy it. Together shows new keys only once.
- Save it as an environment variable. On macOS or Linux run
export TOGETHER_API_KEY="your_api_key". In Windows PowerShell run$env:TOGETHER_API_KEY="your_api_key". - Install the SDK. Run
pip install togetheroruv add together. This guide was checked against together 3.6.0. - Test it. Run the first example below. If it prints a reply, you are ready.
Warning: Never paste the key into code or commit it to Git. Use an environment variable or a .env file that is in .gitignore.
Popular Models and Their IDs (December 2026)
Together uses namespaced IDs like organization/model-name. OpenAI names such as gpt-4o return a 404. These are current serverless chat models from the official catalog, checked on 5 December 2026.
| Model | API model string | Context | Input / 1M | Output / 1M |
|---|---|---|---|---|
| MiniMax M3.1 Flash | MiniMaxAI/MiniMax-M3.1-Flash |
1,048,576 | $0.15 | $0.60 |
| GLM-5.3 Flash | zai-org/GLM-5.3-Flash |
1,048,575 | $0.15 | $0.50 |
| Qwen3.5 9B | Qwen/Qwen3.5-9B |
262,144 | $0.17 | $0.25 |
| NVIDIA Nemotron 3.5 Super VL | nvidia/NVIDIA-Nemotron-3.5-Super-VL |
262,144 | $0.15 | $0.50 |
| DeepSeek V4.1 Flash 1017 | deepseek-ai/DeepSeek-V4.1-Flash-1017 |
1,000,000 | $0.30 | $1.20 |
| Inkling 2 Small | thinkingmachines/Inkling-2-Small |
1,048,576 | $0.30 | $1.00 |
| Tencent Hy4 | tencent/Hy4 |
1,048,576 | $0.834 | $2.501 |
| StepFun Step 5 | stepfun-ai/Step-5 |
1,048,576 | $1.00 | $2.70 |
| GLM-5.3 | zai-org/GLM-5.3 |
1,048,575 | $1.40 | $4.40 |
| Qwen4 Max | Qwen/Qwen4-Max |
1,000,000 | $1.50 | $4.50 |
| Kimi K3.1 Pro | moonshotai/Kimi-K3.1-Pro |
1,048,576 | $2.00 | $10.00 |
| Ternary Bonsai 27B | Prism-ML/Ternary-Bonsai-27B |
262,144 | Free | Free |

Recent changes worth knowing from the official changelog:
- 2 Dec 2026: StepFun Step 5 added to serverless.
- 23 Nov 2026:
DeepSeek-V4.1-Flash-1017-fastadded, a faster tier at $0.60 / $2.40. - 19 Nov 2026: Tencent Hy4 added.
- 17 Nov 2026: Qwen4 Max added.
- 7 Nov 2026: MiniMax M3 left serverless; use MiniMax M3.1 Flash instead.
Note: The Qwen 3.6, 3.7, 3.8 and Qwen4 Max models are “passthrough” models run by a third party. They only work with stream=True, and only after an admin turns off zero data retention. More on that in the privacy section.
Your First Request With the together SDK
The SDK reads TOGETHER_API_KEY from the environment, so you do not need to pass it. Save this as main.py and run python main.py.
from together import Together
client = Together() # reads TOGETHER_API_KEY
response = client.chat.completions.create(
model="MiniMaxAI/MiniMax-M3.1-Flash",
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "What are the top 3 things to do in New York?"},
],
max_tokens=400,
temperature=0.7,
)
print(response.choices[0].message.content)
print("Tokens used:", response.usage.total_tokens)
The response shape matches OpenAI: choices[0].message.content holds the text and usage holds token counts. For async code, import AsyncTogether and await the same call.
Some models think before they answer. The SDK accepts reasoning={"enabled": False} to switch that off on models that support it, and reasoning_effort with "low", "medium" or "high".
Use the OpenAI SDK With Together (base_url)
Already have an OpenAI app? Keep the openai package and change two things: the base URL and the model ID. Our OpenAI API Python tutorial covers that SDK in more depth.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOGETHER_API_KEY"],
base_url="https://api.together.ai/v1",
)
completion = client.chat.completions.create(
model="Qwen/Qwen3.5-9B",
messages=[{"role": "user", "content": "Explain RAG in two sentences."}],
)
print(completion.choices[0].message.content)
According to Together’s OpenAI compatibility page, this works for:
- Supported: chat completions with streaming, vision input,
toolsandtool_choice,response_format, embeddings,images.generate, speech and transcription, and model listing. - Not supported: Assistants/Threads, OpenAI-style fine-tuning and Batch endpoints, and
moderations.create(returns 404).
Since 3 November 2026, Together also accepts the Anthropic Messages API at /v1/messages and the OpenAI Responses API at /v1/responses, but only for a short list of models such as GLM-5.3 and Kimi K3.1 Pro.
The same call with curl
curl https://api.together.ai/v1/chat/completions \
-H "Authorization: Bearer $TOGETHER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "MiniMaxAI/MiniMax-M3.1-Flash",
"messages": [{"role": "user", "content": "Say hello in French"}]
}'
Stream Responses Token by Token
Streaming sends text as it is generated, so chat UIs feel fast. Pass stream=True and loop over the chunks. Each chunk carries a small piece of text in delta.content.
from together import Together
client = Together()
stream = client.chat.completions.create(
model="zai-org/GLM-5.3-Flash",
messages=[{"role": "user", "content": "Write a haiku about GPUs."}],
stream=True,
)
for chunk in stream:
if not chunk.choices:
continue
text = chunk.choices[0].delta.content
if text:
print(text, end="", flush=True)
print()
Tip: Always check if not chunk.choices. Some chunks, such as the final usage chunk, can arrive with an empty choices list.
Function Calling (Tools)
Function calling lets the model ask your code to run a function, such as a weather lookup. Every model in the serverless chat table above lists function calling as supported.
The flow has three steps:
- Describe your tools in the
toolslist using JSON Schema. - Read the tool call from
message.tool_calls, run your function, and add the result as arole: "tool"message. - Call the model again so it can write the final answer.
import json
from together import Together
client = Together()
def get_current_weather(location, unit="celsius"):
# Replace with a real weather API call
return {"location": location, "temperature": 21, "unit": unit}
tools = [{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City and country"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
},
}]
messages = [{"role": "user", "content": "What is the weather in Paris right now?"}]
first = client.chat.completions.create(
model="Qwen/Qwen3.5-9B",
messages=messages,
tools=tools,
tool_choice="auto",
)
msg = first.choices[0].message
if msg.tool_calls:
messages.append(msg.model_dump(exclude_none=True))
for call in msg.tool_calls:
args = json.loads(call.function.arguments)
result = get_current_weather(**args)
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps(result),
})
final = client.chat.completions.create(
model="Qwen/Qwen3.5-9B", messages=messages, tools=tools
)
print(final.choices[0].message.content)
else:
print(msg.content)
The tool_choice parameter accepts "auto" (the default), "none", "required", or an object that forces one named function. Tool calls do not appear in message.content, which can be null on a tool turn.
JSON Mode and Structured Outputs
For data extraction you want valid JSON every time. Together supports response_format with "type": "json_schema" (recommended), the older "json_object", and a "regex" type. Our structured outputs guide compares this across providers.
import json
from pydantic import BaseModel, Field
from together import Together
client = Together()
class Invoice(BaseModel):
vendor: str = Field(description="Company that sent the invoice")
total: float = Field(description="Total amount due")
due_date: str = Field(description="Due date in YYYY-MM-DD")
schema = Invoice.model_json_schema()
text = "Invoice from Acme Ltd. Amount due: 1,250.00 USD by 15 January 2027."
resp = client.chat.completions.create(
model="Qwen/Qwen3.5-9B",
messages=[
{"role": "system", "content": "Only answer in JSON. Follow this schema: " + json.dumps(schema)},
{"role": "user", "content": text},
],
reasoning={"enabled": False},
response_format={
"type": "json_schema",
"json_schema": {"name": "invoice", "schema": schema},
},
)
data = Invoice.model_validate_json(resp.choices[0].message.content)
print(data)
Together’s docs advise putting the schema in the prompt too, as shown above. Note that StepFun Step 5 is marked as not supporting structured outputs in the catalog.
Images and Embeddings (Quick Look)
Generate an image
Image models use client.images.generate. Calls need a positive credit balance. Prices range from about $0.0017 per image (Juggernaut Lightning Flux) to $0.134 (Gemini 3 Pro Image at 1K or 2K).
from together import Together
client = Together()
img = client.images.generate(
model="black-forest-labs/FLUX.2-dev",
prompt="A cozy reading nook with warm lamp light, watercolor style",
width=1024,
height=768,
n=1,
)
print(img.data[0].url)
Warning: Every image model in Together’s current catalog is a passthrough model. With zero data retention on (the default for new organizations), image calls return a 403 with the code third_party_data_sharing_blocked until an admin changes privacy settings.
Embeddings
The SDK still has client.embeddings.create(model=..., input=...), and it is OpenAI-compatible. However, the serverless catalog and the pricing page listed no embedding models when we checked on 5 December 2026, after older models such as intfloat/multilingual-e5-large-instruct were retired in September.
Run tg models public --search embed or check the catalog before you build on it. If nothing is listed, a dedicated provider like our OpenAI embeddings tutorial covers an alternative.
Serverless vs Dedicated Endpoints
Serverless means shared GPUs and per-token billing. Dedicated model inference (DMI) gives you your own replicas, billed by the minute whether or not they get traffic. The API call is the same; only the model string changes.
| Feature | Serverless | Dedicated endpoint |
|---|---|---|
| Billing | Per token | Per minute, per ready replica |
| Minimum cost | None (pay for tokens used) | H100 at $5.49/hour, about $132/day |
| Rate limits | Best effort, may throttle | Bounded by your hardware and autoscaling |
| Models | Together’s serverless catalog | Wider catalog, plus your fine-tuned models |
| Best for | Prototypes, low or bursty traffic | Steady, high-volume production |
To deploy with the Together CLI (installed with the SDK), the docs show:
export TOGETHER_PROJECT_ID=your_project_id
tg endpoints deploy google/gemma-4-E4B-it --endpoint my-endpoint
tg endpoints get <ENDPOINT_ID>
tg endpoints rm <ENDPOINT_ID> --force
Pass the printed endpoint string (your-project-slug/my-endpoint) as model. Delete or scale to zero when idle, because a running replica bills even with no requests.
Pricing Table and a Worked Cost Example
Prices below are per 1 million tokens from Together’s pricing page, checked 5 December 2026. Cached input applies when the start of your prompt repeats.
| Model | Input | Cached input | Output |
|---|---|---|---|
| MiniMax M3.1 Flash | $0.15 | $0.015 | $0.60 |
| GLM-5.3 Flash | $0.15 | $0.03 | $0.50 |
| gpt-oss-120B | $0.15 | n/a | $0.60 |
| DeepSeek V4.1 Flash | $0.30 | $0.006 | $1.20 |
| Beam 1.0 501B A23B | $0.40 | $0.04 | $1.20 |
| Muse Spark Open 816B A42B | $1.25 | $0.15 | $4.25 |
| GLM-5.3 | $1.40 | $0.26 | $4.40 |
| Qwen4 Max | $1.50 | $0.075 | $4.50 |
| Kimi K3.1 Pro | $2.00 | $0.20 | $10.00 |
| Kimi K3 | $3.00 | $0.30 | $15.00 |
US-only processing via us-api.together.ai costs 25% more than these rates.
Worked example: a support chatbot
Say your bot handles 1,000 requests a day, each with 2,000 input tokens and 500 output tokens. That is 2 million input and 0.5 million output tokens daily.
| Model | Input cost/day | Output cost/day | Per day | Per 30 days |
|---|---|---|---|---|
| MiniMax M3.1 Flash | 2 x $0.15 = $0.30 | 0.5 x $0.60 = $0.30 | $0.60 | $18.00 |
| DeepSeek V4.1 Flash | 2 x $0.30 = $0.60 | 0.5 x $1.20 = $0.60 | $1.20 | $36.00 |
| Kimi K3.1 Pro | 2 x $2.00 = $4.00 | 0.5 x $10.00 = $5.00 | $9.00 | $270.00 |
| Dedicated 1x H100 | $5.49 x 24 hours | about $132 | about $3,950 | |
If 1,500 of the 2,000 input tokens are a repeated system prompt that gets cached, MiniMax M3.1 Flash drops to about $0.40 a day: 1.5M x $0.015 plus 0.5M x $0.15 plus $0.30 output. At this volume serverless wins easily; dedicated only pays off when a replica stays busy most of the day.
Rate Limits and Other Limits
Together’s current rate limits page does not publish fixed requests-per-minute tiers for serverless. It says most users will not hit limits, but it may throttle during high demand to protect speed. Our LLM API rate limits guide compares this with other providers.
| Limit | What Together says |
|---|---|
| Serverless rate limits | Best effort; may return 429 or 503 under heavy load |
| Model-specific limits | Custom limits possible on very popular models |
| Guaranteed throughput | Provisioned throughput with an SLA (contact sales) |
| Enterprise / Scale contracts | Purchased limits stay until the contract ends |
| Audio upload size | 80 MB direct upload; use a URL for larger files |
| Context window | Up to about 1M tokens on many models (see model table) |
| Balance | API access stops at zero balance |
Here is a simple retry wrapper with exponential backoff using the SDK’s error classes:
import time
import together
from together import Together
client = Together(max_retries=0)
def chat_with_retry(messages, model="MiniMaxAI/MiniMax-M3.1-Flash", tries=5):
for attempt in range(tries):
try:
return client.chat.completions.create(model=model, messages=messages)
except (together.RateLimitError, together.InternalServerError) as e:
wait = 2 ** attempt
print(f"Got {e.status_code}, retrying in {wait}s")
time.sleep(wait)
raise RuntimeError("Gave up after retries")
print(chat_with_retry([{"role": "user", "content": "Hi"}]).choices[0].message.content)
The SDK also retries some errors on its own by default; the max_retries option controls that.
Privacy, ZDR and the November Incident
Zero data retention (ZDR) is the default for new Together organizations, so prompts and responses are not stored. Turning on prompt storage disables ZDR, and that is required to use passthrough models.
On 21 November 2026, Together published a security notice saying stored prompt samples from June and July 2026 were downloaded after a credential leaked. We cover the timeline and what to check in our AI prompt leaks report.
Note: Whatever provider you use, never put live passwords or API keys in prompts. Coding agents that read .env files are the most common way secrets end up there.
Troubleshooting: Common Errors and Fixes
These codes and fixes come from Together’s error codes page, plus messages listed in the model docs.
| Error | Likely cause | Fix |
|---|---|---|
| 400 Invalid Request | Bad JSON, or input plus max_tokens exceeds the context length |
Lower max_tokens or shorten the prompt |
400 streaming_required |
Passthrough chat model called without streaming | Set stream=True |
| 401 Authentication Error | Wrong or missing key | Check TOGETHER_API_KEY is set in the same shell |
| 402 Payment Required | Balance is zero | Add credits; wait up to 5 minutes for the balance to update |
403 third_party_data_sharing_blocked |
Passthrough model with ZDR on | Admin enables prompt storage and passthrough models, or pick another model |
| 404 Not Found | Wrong URL or a retired model ID (for example gpt-4o or MiniMax M3) |
Copy the ID from the current catalog |
| 413 Request Entity Too Large | Request body too big | Send large images or audio as a URL |
| 429 Too Many Requests | Serverless throttling or GPU quota | Slow down, spread bursts, use exponential backoff |
| 500 / 503 / 504 / 524 | Server error, overload or timeout | Wait briefly and retry with backoff |
| 529 Overloaded | Model hit its maximum replica count | Retry with backoff; contact support if it persists |
Tip: If you upgraded from an old together 1.x or 2.x script and things broke, note that SDK 3.0 (22 Oct 2026) was a breaking release. Reinstall with pip install -U together and compare against the examples above.
Frequently Asked Questions
Is the Together AI API free?
No. Together has no free trial, and you must buy at least $15 of credits before you can create an API key. After that, one model (Ternary Bonsai 27B) is listed as free to call.
What is the Together AI base URL for the OpenAI SDK?
Use https://api.together.ai/v1 as the base_url and your Together key as api_key. Model names must be Together IDs such as Qwen/Qwen3.5-9B.
Which Together AI model should I start with?
MiniMax M3.1 Flash is used in Together’s own quickstart and costs $0.15 / $0.60 per million tokens. For harder tasks, try Kimi K3.1 Pro or GLM-5.3.
Does Together AI support function calling and JSON mode?
Yes. Pass tools and tool_choice for function calling, and response_format with a JSON schema for structured outputs. The catalog marks which models support each.
What are Together AI’s rate limits?
Together does not publish fixed serverless RPM numbers. It may throttle with 429 or 503 errors under high demand, and offers provisioned throughput for guaranteed capacity.
When should I use a dedicated endpoint?
When traffic is steady enough to keep a GPU busy most of the day, or you need predictable latency or a fine-tuned model. An H100 replica costs $5.49 an hour, about $3,950 a month if left running.
Is my data safe on Together AI?
New organizations have zero data retention on by default. Together reported a prompt sample leak covering June and July 2026, so avoid sending secrets in prompts on any provider.
Sources
- Together AI docs: Quickstart
- Together AI docs: Serverless available models
- Together AI pricing
- Together AI docs: Credits
- Together AI docs: OpenAI compatibility
- Together AI docs: Call functions
- Together AI docs: Structured outputs
- Together AI docs: Dedicated model inference pricing
- Together AI docs: Rate limits
- Together AI docs: Error codes
- Together AI docs: Changelog
- PyPI: together 3.6.0



