> ## Documentation Index
> Fetch the complete documentation index at: https://docs.together.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Mastra quickstart

> Install Mastra, point an agent at Together AI, and generate a response from a serverless model.

[Mastra](https://mastra.ai) 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:

```bash theme={null}
pnpm dlx create-mastra@latest
```

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:

```bash theme={null}
TOGETHER_API_KEY=your_api_key
```

## 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:

```typescript src/mastra/agents/weather-agent.ts theme={null}
import { Agent } from "@mastra/core/agent";
import { weatherTool } from "../tools/weather-tool";

export const weatherAgent = new Agent({
  name: "Weather Agent",
  instructions: `
      You are a helpful weather assistant that provides accurate weather
      information and can help plan activities based on the weather.
      Use the weatherTool to fetch current weather data.
`,
  model: "togetherai/moonshotai/Kimi-K3",
  tools: { weatherTool },
});
```

Any [serverless model](https://docs.together.ai/docs/serverless/models.md) works here. Kimi K3 reasons by default. To turn reasoning off for a call, pass provider options through `generate`:

```typescript TypeScript theme={null}
const response = await weatherAgent.generate(
  "What's the weather in San Francisco today?",
  {
    providerOptions: {
      togetherai: { reasoning: { enabled: false } },
    },
  },
);

console.log(response.text);
```

> [!NOTE]
>
> 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:

```bash npm theme={null}
npm run dev
```

```bash yarn theme={null}
yarn dev
```

```bash pnpm theme={null}
pnpm dev
```

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

## Next steps

> [card] [Mastra documentation](https://mastra.ai/docs)
>
> Build workflows, tools, and memory-backed agents with Mastra.

> [card] [Serverless models](https://docs.together.ai/docs/serverless/models.md)
>
> Browse the full catalog of models you can pass to the model router.

> [card] [Vercel AI SDK quickstart](https://docs.together.ai/docs/using-together-with-vercels-ai-sdk.md)
>
> Use the AI SDK that powers Mastra's model layer directly.

> [card] [Next.js chat quickstart](https://docs.together.ai/docs/nextjs-chat-quickstart.md)
>
> Build a streaming chat app with Together AI and Next.js.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.