Method 1: Interactive setup (recommended)
The easiest way to authenticate is using the Modal CLI’s interactive setup:Run the setup command
Run the setup wizard to authenticate:This will:
- Open your browser to log in or create a Modal account
- Generate API credentials
- Save them to
~/.modal.toml
The configuration file is saved to
~/.modal.toml by default. You can customize this location using the MODAL_CONFIG_PATH environment variable.Method 2: Environment variables
For automated environments, CI/CD pipelines, or production deployments, use environment variables:Get your API credentials
Log in to your Modal dashboard and create a new token. You’ll receive:
- A Token ID (starts with
ak-) - A Token Secret (starts with
as-)
Set environment variables
Export the credentials as environment variables:For production, add these to your deployment environment or secrets manager.
Programmatic authentication
You can also pass credentials directly when creating a client:- TypeScript
- Go
Configuration file location
By default, the SDKs look for credentials in~/.modal.toml. You can customize this location:
~/.modal.toml
Credential precedence
The SDKs check for credentials in this order:- Programmatic credentials passed to the client constructor
- Environment variables (
MODAL_TOKEN_IDandMODAL_TOKEN_SECRET) - Configuration file at
~/.modal.tomlor$MODAL_CONFIG_PATH
Managing multiple accounts
If you need to work with multiple Modal accounts, you can:- Use different configuration file paths with
MODAL_CONFIG_PATH - Create separate environment variable sets for each account
- Pass different credentials programmatically to different client instances
Troubleshooting
Authentication errors
If you see authentication errors:Verify token is active
Log in to your Modal dashboard and confirm the token is still active and not expired.
Permission errors
If you get permission errors when accessing resources:- Verify that your token has the necessary permissions
- Check that you’re using the correct workspace/organization
- Ensure the resources you’re trying to access exist and you have access to them
Security best practices
Never commit credentials
Add
.modal.toml and credential files to .gitignoreUse environment variables
In production, use secrets managers or environment variables
Rotate tokens regularly
Generate new tokens periodically and revoke old ones
Use minimal permissions
Create tokens with only the permissions you need
Next steps
Now that you’re authenticated, you’re ready to start building:Quick start guide
Build your first Modal application