Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

Together AI logoTogether 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);
}
info

Mastra uses the OpenAI-compatible /chat/completions endpoint. Some provider-specific features may not be available. Check the Together AI documentation for details.

ModelsDirect link to Models

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
togetherai/deepseek-ai/DeepSeek-R1164K$3$7
togetherai/deepseek-ai/DeepSeek-V3131K$1$1
togetherai/meta-llama/Llama-3.3-70B-Instruct-Turbo131K$0.88$0.88
togetherai/moonshotai/Kimi-K2-Instruct131K$1$3
togetherai/openai/gpt-oss-120b131K$0.15$0.60
togetherai/Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8262K$2$2
6 available models

Advanced ConfigurationDirect link to Advanced Configuration

Custom HeadersDirect link to Custom Headers

const agent = new Agent({
name: "custom-agent",
model: {
url: "https://api.together.xyz/v1",
id: "togetherai/Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8",
apiKey: process.env.TOGETHER_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});

Dynamic Model SelectionDirect link to 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 InstallationDirect link to 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.