Together AI
Access 26 Together AI models through Mastra's model router. Authentication is handled automatically using the TOGETHER_API_KEY environment variable.
Learn more in the Together AI documentation.
.env
TOGETHER_API_KEY=your-api-key
src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";
const agent = new Agent({
id: "my-agent",
name: "My Agent",
instructions: "You are a helpful assistant",
model: "togetherai/MiniMaxAI/MiniMax-M3.1-Flash"
});
// Generate a response
const response = await agent.generate("Hello!");
// Stream a response
const stream = await agent.stream("Tell me a story");
for await (const chunk of stream) {
console.log(chunk);
}
ModelsDirect link to Models
| Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
|---|---|---|---|---|---|---|---|---|
togetherai/deepseek-ai/DeepSeek-V4.1-Flash | 1.0M | $0.30 | $1 | |||||
togetherai/deepseek-ai/DeepSeek-V4.1-Flash-1017 | 1.0M | $0.30 | $1 | |||||
togetherai/deepseek-ai/DeepSeek-V4.1-Flash-1017-fast | 1.0M | $0.60 | $2 | |||||
togetherai/elorian-labs/glimpse-1.0 | 262K | $0.60 | $3 | |||||
togetherai/meta-models/Muse-Glimmer-30B | 131K | $0.35 | $2 | |||||
togetherai/meta-models/Muse-Spark-Open-816B-A42B | 1.0M | $1 | $4 | |||||
togetherai/MiniMaxAI/MiniMax-M3.1-Flash | 1.0M | $0.15 | $0.60 | |||||
togetherai/moonshotai/Kimi-K3 | 1.0M | $3 | $15 | |||||
togetherai/moonshotai/Kimi-K3.1-Pro | 1.0M | $2 | $10 | |||||
togetherai/nvidia/NVIDIA-Nemotron-3.5-Super-VL | 262K | $0.15 | $0.50 | |||||
togetherai/Qwen/Qwen3.5-9B | 262K | $0.17 | $0.25 | |||||
togetherai/Qwen/Qwen3.6-Plus | 1.0M | $0.50 | $3 | |||||
togetherai/Qwen/Qwen3.7-Max | 1.0M | $3 | $8 | |||||
togetherai/Qwen/Qwen3.7-Plus | 1.0M | $0.32 | $1 | |||||
togetherai/Qwen/Qwen3.8-Flash | 1.0M | $0.15 | $0.47 | |||||
togetherai/Qwen/Qwen4-Max | 1.0M | $2 | $5 | |||||
togetherai/reflection/Beam-1.0-501B-A23B | 1.0M | $0.40 | $1 | |||||
togetherai/ricursive-ai/Ripple-65B-Preview | 131K | $0.20 | $0.60 | |||||
togetherai/tencent/Hy4 | 1.0M | $0.83 | $3 | |||||
togetherai/thinkingmachines/Inkling-2-Small | 1.0M | $0.30 | $1 | |||||
togetherai/zai-org/GLM-5.2 | 1.0M | $1 | $4 | |||||
togetherai/zai-org/GLM-5.3 | 1.0M | $1 | $4 | |||||
togetherai/zai-org/GLM-5.3-Flash | 1.0M | $0.15 | $0.50 |
Model availability, capabilities, context windows, and pricing are sourced from models.dev and may change.
Advanced configurationDirect link to Advanced configuration
Custom headersDirect link to Custom headers
src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";
const agent = new Agent({
id: "custom-agent",
name: "custom-agent",
model: {
id: "togetherai/MiniMaxAI/MiniMax-M3.1-Flash",
apiKey: process.env.TOGETHER_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});
Dynamic model selectionDirect link to Dynamic model selection
src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";
const agent = new Agent({
id: "dynamic-agent",
name: "Dynamic Agent",
model: ({ requestContext }) => {
const useAdvanced = requestContext.task === "complex";
return useAdvanced
? "togetherai/zai-org/GLM-5.3-Flash"
: "togetherai/MiniMaxAI/MiniMax-M3.1-Flash";
}
});