docs/src/content/en/models/providers/togetherai.mdx
Access 17 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.
TOGETHER_API_KEY=your-api-key
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-M2.5"
});
// 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);
}
<ProviderModelsTable models={[ { "model": "togetherai/deepseek-ai/DeepSeek-R1", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": true, "contextWindow": 163839, "maxOutput": 163839, "inputCost": 3, "outputCost": 7 }, { "model": "togetherai/deepseek-ai/DeepSeek-V3", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 131072, "maxOutput": 131072, "inputCost": 1.25, "outputCost": 1.25 }, { "model": "togetherai/deepseek-ai/DeepSeek-V3-1", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 131072, "maxOutput": 131072, "inputCost": 0.6, "outputCost": 1.7 }, { "model": "togetherai/essentialai/Rnj-1-Instruct", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 32768, "maxOutput": 32768, "inputCost": 0.15, "outputCost": 0.15 }, { "model": "togetherai/meta-llama/Llama-3.3-70B-Instruct-Turbo", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 131072, "maxOutput": 131072, "inputCost": 0.88, "outputCost": 0.88 }, { "model": "togetherai/MiniMaxAI/MiniMax-M2.5", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 204800, "maxOutput": 131072, "inputCost": 0.3, "outputCost": 1.2 }, { "model": "togetherai/moonshotai/Kimi-K2-Instruct", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 131072, "maxOutput": 131072, "inputCost": 1, "outputCost": 3 }, { "model": "togetherai/moonshotai/Kimi-K2.5", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 262144, "maxOutput": 262144, "inputCost": 0.5, "outputCost": 2.8 }, { "model": "togetherai/openai/gpt-oss-120b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 131072, "maxOutput": 131072, "inputCost": 0.15, "outputCost": 0.6 }, { "model": "togetherai/Qwen/Qwen3-235B-A22B-Instruct-2507-tput", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 262144, "maxOutput": 262144, "inputCost": 0.2, "outputCost": 0.6 }, { "model": "togetherai/Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 262144, "maxOutput": 262144, "inputCost": 2, "outputCost": 2 }, { "model": "togetherai/Qwen/Qwen3-Coder-Next-FP8", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 262144, "maxOutput": 262144, "inputCost": 0.5, "outputCost": 1.2 }, { "model": "togetherai/Qwen/Qwen3-Next-80B-A3B-Instruct", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 262144, "maxOutput": 262144, "inputCost": 0.15, "outputCost": 1.5 }, { "model": "togetherai/Qwen/Qwen3.5-397B-A17B", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 262144, "maxOutput": 130000, "inputCost": 0.6, "outputCost": 3.6 }, { "model": "togetherai/zai-org/GLM-4.6", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 200000, "maxOutput": 200000, "inputCost": 0.6, "outputCost": 2.2 }, { "model": "togetherai/zai-org/GLM-4.7", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 200000, "inputCost": 0.45, "outputCost": 2 }, { "model": "togetherai/zai-org/GLM-5", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 202752, "maxOutput": 131072, "inputCost": 1, "outputCost": 3.2 } ]} />
const agent = new Agent({
id: "custom-agent",
name: "custom-agent",
model: {
id: "togetherai/MiniMaxAI/MiniMax-M2.5",
apiKey: process.env.TOGETHER_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});
const agent = new Agent({
id: "dynamic-agent",
name: "Dynamic Agent",
model: ({ requestContext }) => {
const useAdvanced = requestContext.task === "complex";
return useAdvanced
? "togetherai/zai-org/GLM-5"
: "togetherai/MiniMaxAI/MiniMax-M2.5";
}
});
This provider can also be installed directly as a standalone package, which can be used instead of the Mastra model router string. View the package documentation for more details.
npm install @ai-sdk/togetherai
For detailed provider-specific documentation, see the AI SDK Together AI provider docs.