Together AI
Access 6 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";
const agent = new Agent({
name: "my-agent",
instructions: "You are a helpful assistant",
model: "togetherai/Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8"
});
// 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);
}
Mastra uses the OpenAI-compatible /chat/completions
endpoint. Some provider-specific features may not be available. Check the Together AI documentation for details.
Models
Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
---|---|---|---|---|---|---|---|---|
togetherai/deepseek-ai/DeepSeek-R1 | 164K | $3 | $7 | |||||
togetherai/deepseek-ai/DeepSeek-V3 | 131K | $1 | $1 | |||||
togetherai/meta-llama/Llama-3.3-70B-Instruct-Turbo | 131K | $0.88 | $0.88 | |||||
togetherai/moonshotai/Kimi-K2-Instruct | 131K | $1 | $3 | |||||
togetherai/openai/gpt-oss-120b | 131K | $0.15 | $0.60 | |||||
togetherai/Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8 | 262K | $2 | $2 |
Advanced Configuration
Custom Headers
const agent = new Agent({
name: "custom-agent",
model: {
url: "https://api.together.xyz/v1",
modelId: "Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8",
apiKey: process.env.TOGETHER_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});
Dynamic Model Selection
const agent = new Agent({
name: "dynamic-agent",
model: ({ runtimeContext }) => {
const useAdvanced = runtimeContext.task === "complex";
return useAdvanced
? "togetherai/openai/gpt-oss-120b"
: "togetherai/Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8";
}
});
Direct Provider Installation
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 .