Quickstart: Using Mastra with Together AI ↗
noOriginal Documentation
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.
This guide will walk you through how to use Together models with Mastra.
Mastra is a framework for building and deploying AI-powered features using a modern JavaScript stack powered by the Vercel AI SDK. Integrating with Together AI provides access to a wide range of models for building intelligent agents.
Getting started#
Create a new Mastra project#
First, create a new Mastra project using the CLI:
pnpm dlx create-mastra@latestDuring the setup, the system prompts you to name your project, choose a default provider, and more. Feel free to use the default settings.
Install dependencies#
To use Together AI with Mastra, install the required packages:
npm i @ai-sdk/togetherai
```
```bash
yarn add @ai-sdk/togetherai
```
```bash
pnpm add @ai-sdk/togetherai
```
3. ### Configure environment variables
Create or update your `.env` file with your Together AI API key:
```bash
TOGETHER_API_KEY=your-api-key-hereConfigure your agent to use Together AI#
Now, update your agent configuration file, typically
src/mastra/agents/weather-agent.ts, to use Together AI models:import 'dotenv/config'; import { Agent } from '@mastra/core/agent'; import { createTogetherAI } from '@ai-sdk/togetherai'; const together = createTogetherAI({ apiKey: process.env.TOGETHER_API_KEY ?? "", }); export const weatherAgent = new Agent({ name: 'Weather Agent', instructions: ` You are a helpful weather assistant that provides accurate weather information and can help planning activities based on the weather. Use the weatherTool to fetch current weather data. `, model: together("zai-org/GLM-4.5-Air-FP8"), tools: { weatherTool }, // ... other configuration }); (async () => { try { const response = await weatherAgent.generate( "What's the weather in San Francisco today?", ); console.log('Weather Agent Response:', response.text); } catch (error) { console.error('Error invoking weather agent:', error); } })();Running the application#
Since your agent is now configured to use Together AI, run the Mastra development server:
npm run dev
```
```bash
yarn dev
```
```bash
pnpm dev
```
Open the [Mastra Playground and Mastra API](https://mastra.ai/en/docs/server-db/local-dev-playground) to test your agents, workflows, and tools.
## Next Steps
* Explore the [Mastra documentation](https://mastra.ai) for more advanced features
* Check out [Together AI's model documentation](https://docs.together.ai/docs/serverless-models) for the latest available models
* Learn about building workflows and tools in Mastra