跳到主要内容
非官方简体中文翻译,内容版权归 Mastra 所有,遵循 Apache-2.0 许可。

Together AI logoTogether AI

Access 32 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/LiquidAI/LFM2-24B-A2B"
});

// 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);
}

Models
Models的直接链接

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
togetherai/deepseek-ai/DeepSeek-V4-Flash-07311.0M$0.14$0.28
togetherai/deepseek-ai/DeepSeek-V4-Pro-08131.0M$1$4
togetherai/deepseek-ai/DeepSeek-V4.1-Flash1.0M$0.30$1
togetherai/LiquidAI/LFM2-24B-A2B33K$0.03$0.12
togetherai/meta-llama/Llama-3.3-70B-Instruct-Turbo131K$1$1
togetherai/meta-models/Muse-Spark-Open-816B-A42B1.0M$1$4
togetherai/MiniMaxAI/MiniMax-M2.7197K$0.30$1
togetherai/MiniMaxAI/MiniMax-M3524K$0.30$1
togetherai/moonshotai/Kimi-K31.0M$3$15
togetherai/nvidia/nemotron-3-ultra-550b-a55b512K$0.60$4
togetherai/nvidia/NVIDIA-Nemotron-3.5-Super-VL262K$0.15$0.50
togetherai/openai/gpt-oss-120b131K$0.15$0.60
togetherai/Qwen/Qwen2.5-7B-Instruct-Turbo33K$0.30$0.30
togetherai/Qwen/Qwen3.5-9B262K$0.17$0.25
togetherai/Qwen/Qwen3.6-Plus1.0M$0.50$3
togetherai/Qwen/Qwen3.7-Max1.0M$1$4
togetherai/reflection/Beam-1.0-501B-A23B1.0M$0.40$1
togetherai/thinkingmachines/Inkling524K$1$4
togetherai/zai-org/GLM-5.21.0M$1$4
togetherai/zai-org/GLM-5.31.0M$1$4
togetherai/zai-org/GLM-5.3-Flash1.0M$0.15$0.50
21 available models

Model availability, capabilities, context windows, and pricing are sourced from models.dev and may change.

Advanced configuration
Advanced configuration的直接链接

Custom headers
Custom headers的直接链接

src/mastra/agents/my-agent.ts
const agent = new Agent({
id: "custom-agent",
name: "custom-agent",
model: {
id: "togetherai/LiquidAI/LFM2-24B-A2B",
apiKey: process.env.TOGETHER_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});

Dynamic model selection
Dynamic model selection的直接链接

src/mastra/agents/my-agent.ts
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/LiquidAI/LFM2-24B-A2B";
}
});