Mastra Init
The mastra init
command helps you add Mastra to an existing project. This command provides an interactive setup process to configure Mastra in your project.
Using the CLI
Install the CLI
First, install the mastra CLI.
npm i -g mastra
Initialize Mastra
To initialize mastra in your project by following the interactive setup, run:
mastra init
Set Up your API Key
Add the API key for your configured LLM provider in your .env
file.
OPENAI_API_KEY=<your-openai-key>
Non-Interactive Mode
If you prefer to run the command with flags (non-interactive mode) and include the example code, you can use:
mastra init --dir src/mastra --components agents,tools --llm openai --example
This allows you to specify your preferences upfront without being prompted.