Environment Variables
Store API keys and configuration safely using .env files in your Motia apps.
Environment Variables
Environment variables let you store API keys, database URLs, and other configuration outside your code. This keeps sensitive information secure and makes it easy to use different settings for development and production.
Quick Setup
1. Create a .env File
Create a .env file in your project root:
2. Add to .gitignore
Make sure you never commit your .env file:
3. Create Template for Your Team
Using Environment Variables in Steps
TypeScript/JavaScript
Python
Redis Configuration
Motia uses Redis for internal coordination. By default, it includes an embedded in-memory Redis server for development, so you don't need to install or configure Redis separately.
Environment Variables
If you want to use your own Redis instance (created with --skip-redis flag or for production), you can configure it using these environment variables:
| Variable | Description | Default |
|---|---|---|
MOTIA_REDIS_HOST | Redis host | 127.0.0.1 |
MOTIA_REDIS_PORT | Redis port | 6379 |
MOTIA_REDIS_PASSWORD | Redis password | - |
MOTIA_REDIS_USERNAME | Redis username (Redis 6.0+) | - |
MOTIA_REDIS_DB | Redis database number | 0 |
MOTIA_DISABLE_MEMORY_SERVER | Disable embedded Redis | false |
Example: Using External Redis
Alternatively, you can configure Redis in your motia.config.ts file. See the CLI documentation for more details.
Deployment
When you deploy your app, set environment variables through your hosting platform:
Motia Cloud
Important Security Tips
🔒 Keep Your Keys Safe
- Never commit
.envfiles to git - Use different API keys for development and production
- Don't share API keys in code or messages
That's it! Environment variables are simple - just put them in .env and use process.env.VARIABLE_NAME in your code.