Skip to main content

Prerequisites

Installation

Install the CLI globally from npm:
The package name is sendlayer-cli. The sendlayer package on npm is the Node.js SDK, which doesn’t include the CLI.
Confirm the installation by checking the version:

Authentication

Run sendlayer login and paste your API key when prompted. The CLI checks the key against the SendLayer API before saving it.
In CI and other non-interactive environments, set the SENDLAYER_API_KEY environment variable instead. Every command reads it.
The CLI looks for an API key in this order:
  1. The --api-key flag
  2. The SENDLAYER_API_KEY environment variable
  3. Credentials saved by sendlayer login
Avoid passing your key with --api-key or login --key on a shared machine. A key on the command line is visible in your shell history and to other users through ps.
To see which key is active and where it came from, run whoami. The CLI always masks the key:

Profiles

Save keys for several accounts or environments under named profiles. Then pass --profile to any command to use that key:
The first profile you save becomes the default. Any command run without --profile uses the default profile. If you log out of the default profile, the CLI promotes another saved profile and tells you which one.
The CLI stores credentials with file mode 0600 at:
  • macOS and Linux: ~/.config/sendlayer/credentials.json (or $XDG_CONFIG_HOME/sendlayer/credentials.json)
  • Windows: %APPDATA%\sendlayer\credentials.json

Send an email

Pass the sender, recipients, subject, and body as flags:
When SendLayer accepts the email, the CLI prints its message ID:
The --from address must use a domain you’ve authorized in SendLayer. Use a plain email address, or Name <email> to set a display name.

HTML and plain text

Pass the body inline with --html and --text, or read it from a file with --html-file and --text-file. When you send both, email clients that don’t render HTML show the plain-text version.

Recipients, attachments, and headers

  • --to, --cc, --bcc, and --reply-to take a comma-separated list. Pass each of these flags once.
  • Repeat --attachment, --header, and --tag to add more than one.
  • --attachment takes path[:mime[:disposition[:filename]]]. If you leave out the MIME type, the CLI guesses it from the file extension. The disposition is attachment (the default) or inline.
  • --header takes Key=Value.

Send from a JSON file

For complex emails, put the full payload in a JSON file and pass it with --file. The file uses the same fields as the Node.js SDK.
email.json

Query events

List delivery and engagement events, with optional filters:

Manage webhooks

Webhook event types are bounce, click, open, unsubscribe, complaint, and delivery. For the payload each one sends, see Managing Webhooks.

Test webhooks locally

webhooks listen receives webhook events on your machine while you develop. It needs a public HTTPS URL that tunnels to a local port, such as one from ngrok.
1

Start a tunnel

Expose a local port. The CLI listens on port 4000 by default. Use --port to change it.
2

Start the listener

In another terminal, pass the tunnel URL. Add --forward-to to send each event on to your local app.
The CLI creates one webhook per event type and prints each event as it arrives. To listen for specific types only, add --events bounce,click.
3

Stop the listener

Press Ctrl+C. The CLI deletes every webhook it created. If a previous run crashed, the next run offers to clean up the leftover webhooks.

Use the CLI with AI agents and scripts

In a terminal, the CLI prints readable output. When its output goes to a pipe, a CI job, or an AI coding agent such as Claude Code, Cursor, or Codex, it switches to JSON automatically. Add --json to any command to force JSON output. JSON output works with tools like jq. This command lists the recipients of failed emails:
In JSON mode, the CLI writes errors to stderr in this format:
For the codes inside details.response.Errors, see Error Codes.

Exit codes

Scripts and agents branch on the exit code without parsing the error message:

GitHub Actions example

Store your API key as a repository secret named SENDLAYER_API_KEY. Then install and run the CLI in a workflow step:
.github/workflows/release.yml
Pin the CLI version in CI so a new release doesn’t change your pipeline’s behavior unexpectedly.

Get help

Add --help to any command to see its flags and examples:
Report bugs or request features in the SendLayer CLI GitHub repository.

FAQ

Both give AI tools access to SendLayer. The MCP server adds SendLayer tools to any app that supports MCP, including chat apps such as Claude Desktop. The CLI runs as a shell command, so it also works in scripts, cron jobs, and CI pipelines.
The CLI switches to JSON when its output isn’t a terminal, such as when you pipe it to another command. Run the command directly in a terminal to see readable output.
Save each account’s key under its own profile with sendlayer login --profile <name>. Then pass --profile <name> to any command. Run sendlayer whoami to check which profile is active.