This guide is for autonomous AI agents that need direct access to email, calendar, and contacts through shell commands. Follow the steps below — do as much as you can yourself, and only ask the user when you hit a step that requires a browser.
If you are a coding agent helping a developer build a SaaS application, see Quickstart: AI coding agents instead.
Pick an identity model
Section titled “Pick an identity model”Before you set up the CLI, decide how the agent should appear in the world. There are two common patterns.
- Share an existing inbox and calendar. The agent acts on an account that already belongs to a human — the human’s own Gmail, Outlook, or IMAP. Replies go to the human, events appear on the human’s calendar. Use this when the agent is an assistant to one person. It’s what this quickstart sets up — see also Share your email with your agent and Share your calendar with your agent.
- Give the agent its own inbox and calendar. The agent has a dedicated
[email protected]mailbox and a dedicated calendar it fully owns — Nylas-hosted, API-driven, no OAuth. Spin one up withnylas agent account create <email>(seenylas agent account listandnylas agent statusfor discovery and health). Use this when the agent has its own identity — a sales agent, a scheduling bot, a shared service mailbox. See Give your agent its own email (Beta) and Give your agent its own calendar (Beta). These run on Nylas Agent Accounts.
Both patterns use the same Nylas grant model, so if you’re writing a custom agent you can mix them — one agent that triages a shared support@ mailbox while acting on its own sales outbox, for example.
Rules for agents
Section titled “Rules for agents”- Always pass
--jsonto get structured output you can parse. Without it, the CLI returns human-formatted text. - Always pass
--yeswhen sending email or deleting anything. Without it, the CLI blocks waiting for confirmation. - Always pass
--limiton list commands to control token consumption. Start with 5, increase if needed. - Prefer the CLI over raw API calls. The CLI handles OAuth token refresh, provider normalization, and pagination for you.
- Do not hardcode grant IDs. Run
nylas auth whoami --jsonto discover the active grant at runtime, or set theNYLAS_GRANT_IDenvironment variable.
Step 1: Check if already set up
Section titled “Step 1: Check if already set up”Before installing anything, check if the CLI is already configured:
nylas auth whoami --jsonIf this returns JSON with email, provider, grant_id, and status, you’re ready. Skip to Step 4.
If the command fails (command not found), continue to Step 2.
If the command runs but returns an error (no active grant), skip to Step 3.
Step 2: Install the CLI
Section titled “Step 2: Install the CLI”Install the CLI yourself:
brew install nylas/nylas-cli/nylasIf Homebrew is not available:
curl -fsSL https://cli.nylas.com/install.sh | bashVerify the install worked:
nylas demo email listThis returns sample data with no credentials required, confirming the binary is working.
Step 3: Set up credentials
Section titled “Step 3: Set up credentials”This is the one step that may need user involvement. Ask the user: “Do you have an existing Nylas API key?”
If yes, do the setup yourself:
nylas init --api-key <NYLAS_API_KEY>For EU data residency:
nylas init --api-key <NYLAS_API_KEY> --region euIf no (or they’re not sure), ask them to run one command. This opens a browser for account creation and SSO login — the only step that requires a human:
Run
nylas initin your terminal. It will open a browser to sign in. Once you’re done, I’ll take it from here.
After either path, verify credentials are working:
nylas auth whoami --jsonExpected output:
{ "provider": "google", "grant_id": "d3f4a5b6-c7d8-9e0f-a1b2-c3d4e5f6g7h8", "status": "valid"}If you need the raw API key for any reason:
nylas auth tokenThis prints the API key as a plain string, nothing else.
Step 4: Verify and start using
Section titled “Step 4: Verify and start using”Run a quick test to confirm everything works:
nylas email list --limit 3 --jsonExpected output (a flat JSON array):
[ { "id": "msg_abc123", "subject": "Learn how to Send Email with Nylas APIs", "snippet": "Send Email with Nylas APIs", "date": 1706811644, "unread": true, "folders": ["INBOX", "UNREAD"] }]If this returns an error, check error.type:
{ "request_id": "5fa64c92-e840-4357-86b9-2aa364d35b88", "error": { "type": "unauthorized", "message": "Unauthorized" }}Common error types: unauthorized (bad/expired key — run nylas dashboard apps apikeys create), not_found_error (invalid grant — run nylas auth login), rate_limit_error (slow down and retry).
You’re now set up. Use the commands below.
Step 5: MCP or CLI commands
Section titled “Step 5: MCP or CLI commands”If your agent supports MCP
Section titled “If your agent supports MCP”For agents that support Model Context Protocol (Claude Code, Claude Desktop, Cursor, Windsurf, VS Code, OpenAI Codex CLI), register the CLI as an MCP server. This gives you 16 email, calendar, and contacts tools without subprocess calls:
nylas mcp install --assistant claude-codenylas mcp install --assistant cursornylas mcp install --assistant windsurfnylas mcp install --assistant vscodenylas mcp install --all # installs for all detected assistantsVerify with nylas mcp status. With MCP active, you don’t need the commands below — the MCP server handles everything.
Email commands
Section titled “Email commands”# List recent emailsnylas email list --limit 5 --json
# List unread emails onlynylas email list --unread --limit 10 --json
# Search for specific emailsnylas email search "meeting agenda" --limit 5 --json
# Read a specific message by IDnylas email read <MESSAGE_ID> --json
# Send an emailnylas email send \ --subject "Meeting follow-up" \ --body "Thanks for the meeting. Here are the action items we discussed." \ --yes
# Send with CC, BCC, or scheduled deliverynylas email send \ --subject "Project update" \ --body "Status report attached." \ --schedule "tomorrow 9am" \ --yesTo follow a conversation across replies, use threads instead of individual messages. The Threads API groups related messages by their In-Reply-To and References headers, so the agent gets the full conversation history in one call. See Email threading for agents for the details.
Calendar commands
Section titled “Calendar commands”# List upcoming eventsnylas calendar events list --days 7 --json
# Create an eventnylas calendar events create \ --title "Sync meeting" \ --start "2026-04-10T10:00:00" \ --end "2026-04-10T10:30:00"
# Find a time that works for multiple peoplenylas calendar find-time \ --duration 30m \ --json
# Natural language schedulingnylas calendar schedule ai "Find 30 minutes with Alice next week"Contacts commands
Section titled “Contacts commands”nylas contacts list --limit 10 --jsonnylas contacts search --query "Alice" --jsonAgent Account commands (Beta)
Section titled “Agent Account commands (Beta)”For agents that need their own Nylas-hosted [email protected] mailbox. Requires a domain registered with Nylas.
# Create an Agent Account (returns the grant ID)
# Create with IMAP/SMTP access enabled
# List every Agent Account on the applicationnylas agent account listnylas agent account list --json
# Get a single Agent Account by ID or email
# Check connector readinessnylas agent statusnylas agent status --json
# List policies and rules attached to accountsnylas agent policy listnylas agent rule list
# Delete by grant ID or email address (--yes skips confirmation)Agent Accounts also appear in nylas auth list with Provider: Nylas. You drive them with the same nylas email ... and nylas calendar ... commands used on connected grants — see Agent Accounts for the full product.
Webhook commands
Section titled “Webhook commands”Subscribe to notifications so your agent reacts to inbound mail, event updates, and other changes in real time. Webhooks work against any grant — connected or Agent Account.
# List the trigger types you can subscribe tonylas webhook triggers
# Create a webhook subscriptionnylas webhook create \ --url https://youragent.example.com/webhooks/nylas \ --triggers "message.created,message.updated"
# List webhooks on the applicationnylas webhook list
# Update an existing webhooknylas webhook update <WEBHOOK_ID>
# Delete a webhook by IDnylas webhook delete <WEBHOOK_ID>Run nylas webhook create --help for the full flag set, or see Using webhooks with Nylas for payload schemas and signature verification.
Account commands
Section titled “Account commands”# See which mailbox you're operating onnylas auth whoami --json
# List all connected mailboxesnylas auth list
# Switch to a different mailboxnylas auth switch
# Connect another email account (requires user -- opens browser)nylas auth loginTroubleshooting
Section titled “Troubleshooting”| Symptom | Fix |
|---|---|
nylas: command not found | Run the install command again, or use the full path (/opt/homebrew/bin/nylas) |
nylas auth whoami returns an error | Ask the user to run nylas init (requires browser) |
error.type: "unauthorized" | Run nylas dashboard apps apikeys create to generate a new API key |
No active application | Ask the user to run nylas init (requires browser) |
| Commands hang | Add --yes to skip confirmation prompts |
| Empty results | Run nylas auth list to check accounts, nylas auth switch to change |
Go deeper
Section titled “Go deeper”When you need to look up API details, endpoints, or provider-specific behavior:
# Curated sitemap for agents (start here)curl https://developer.nylas.com/llms.txt
# Full documentation in one filecurl https://developer.nylas.com/llms-full.txt
# Any single page as clean markdowncurl -H "Accept: text/markdown" https://developer.nylas.com/docs/v3/email/- Nylas CLI on GitHub — source code, issues, and releases
- CLI command reference — every command and flag documented
- CLI guides — 85+ step-by-step guides for email, calendar, MCP, and more
- Build an LLM agent with email tools — wire CLI commands into an agent loop with OpenAI-compatible tool definitions
- Give agents email via MCP — full MCP setup guide
- Audit agent activity — track actions with source detection and compliance exports