Skip to main content
Mastra is a TypeScript framework for building and deploying AI agents, workflows, and tools. Its model router speaks to Together AI directly: pass a togetherai/ model string and Mastra reads your API key from the environment, with no provider package to install.

Step 1: Create a new Mastra project

Create a new Mastra project using the CLI:
During setup, the CLI prompts you to name your project and choose a default provider. The default settings work fine, because the next steps switch the agent to Together AI.

Step 2: Configure environment variables

Add your Together API key to the project’s .env file:

Step 3: Configure your agent to use Together AI

Update your agent configuration file, typically src/mastra/agents/weather-agent.ts, to point the model router at a Together AI model. The format is togetherai/ followed by the model ID:
src/mastra/agents/weather-agent.ts
Any serverless model works here. Kimi K3 reasons by default. To turn reasoning off for a call, pass provider options through generate:
TypeScript
Mastra’s current release expects AI SDK v5 provider packages, so the latest @ai-sdk/togetherai (built for AI SDK v6) fails with AGENT_STREAM_V1_MODEL_NOT_SUPPORTED when passed as a model instance. The togetherai/ model string avoids the version coupling entirely.

Step 4: Run the application

Run the Mastra development server:
The dev server prints a local Mastra Playground URL. Open it to test your agents, workflows, and tools.

Next steps

Mastra documentation

Build workflows, tools, and memory-backed agents with Mastra.

Serverless models

Browse the full catalog of models you can pass to the model router.

Vercel AI SDK quickstart

Use the AI SDK that powers Mastra’s model layer directly.

Next.js chat quickstart

Build a streaming chat app with Together AI and Next.js.