Install the package
Install the Modal SDK in any server-side Node.js, Deno, or Bun project:Requirements
The Modal TypeScript SDK requires Node.js 22 or later.
import or require() in any project:
ES Modules
CommonJS
Authentication
You need to authenticate with Modal before using the SDK. There are two methods:Method 1: Modal CLI (recommended)
The easiest way to authenticate is using the Modal CLI:Run the setup command
- Open your browser to authenticate
- Create a
~/.modal.tomlconfiguration file with your credentials - Set up the default profile
Method 2: Environment variables
For machine environments (CI/CD, production servers), use environment variables:Get your Modal tokens
- Go to https://modal.com/settings/tokens
- Create a new token
- Copy your
token_idandtoken_secret
Configuration
The Modal SDK uses configuration from several sources, in order of priority:- Constructor parameters: Passed directly to
new ModalClient() - Environment variables:
MODAL_TOKEN_ID,MODAL_TOKEN_SECRET, etc. - Configuration file:
~/.modal.toml(default) or custom path viaMODAL_CONFIG_PATH
Configuration file location
The default configuration file is~/.modal.toml. You can customize this:
Available environment variables
| Variable | Description | Default |
|---|---|---|
MODAL_TOKEN_ID | Your Modal token ID | - |
MODAL_TOKEN_SECRET | Your Modal token secret | - |
MODAL_ENVIRONMENT | Environment name | - |
MODAL_SERVER_URL | Modal API server URL | https://api.modal.com:443 |
MODAL_CONFIG_PATH | Path to config file | ~/.modal.toml |
MODAL_PROFILE | Profile name to use | Active profile in config |
MODAL_IMAGE_BUILDER_VERSION | Image builder version | 2024.10 |
MODAL_LOGLEVEL | Logging level | - |
Verify installation
Create a simple test script to verify your installation:test.ts
Next steps
Basic usage
Learn basic patterns and workflows
Client configuration
Configure the ModalClient