CLI

Use @21st-sdk/cli to authenticate, deploy agents, manage environment variables, and inspect logs from your terminal.

Install & Auth

The CLI is usually run with npx. It stores credentials in ~/.an/credentials, or you can pass an API key with the API_KEY_21ST environment variable.

npx @21st-sdk/cli login

# non-interactive
API_KEY_21ST=an_sk_... npx @21st-sdk/cli login --api-key $API_KEY_21ST

Project Layout

The current deploy structure is one agent per folder under agents/. The primary entrypoint is agents/<slug>/index.ts or agents/<slug>/index.js.

agents/
  my-agent/
    index.ts    # or index.js
    template/
      ...

package.json

Use one folder per deployable agent. See Build & Deploy for the full project structure.

Deploy

Deploy scans the agents/ directory, bundles each detected agent, uploads it, and prints a link to the Agents dashboard. Use --agent <slug> if you only want to deploy one agent.

# deploy every agent under agents/
npx @21st-sdk/cli deploy

# deploy only one agent
npx @21st-sdk/cli deploy --agent my-agent

Environment Variables

Use the CLI to list configured environment variable keys, set a single key, or remove a single key for a deployed agent.

# list configured keys
npx @21st-sdk/cli env list my-agent

# set or update one key
npx @21st-sdk/cli env set my-agent OPENAI_API_KEY sk-live-...

# remove one key
npx @21st-sdk/cli env remove my-agent OPENAI_API_KEY

The list command only returns keys, not secret values.

Logs

The CLI can list recent chat sessions, inspect a chat, or fetch one specific thread directly.

# list chats
npx @21st-sdk/cli logs my-agent

# inspect one chat
npx @21st-sdk/cli logs my-agent <chat-id>

# inspect one thread
npx @21st-sdk/cli logs my-agent <chat-id> <thread-id>

# machine-readable output
npx @21st-sdk/cli logs my-agent --json

Filtering & Pagination

The logs list supports status filtering, search, date filtering, and cursor-based pagination.

FlagDescription
--status active|errorFilter chats by status
--search TEXTSearch by chat ID or sandbox ID
--since ISOOnly include chats created at or after the timestamp
--until ISOOnly include chats created at or before the timestamp
--limit NPage size, from 1 to 100
--cursor UUIDFetch the next page while keeping the same filters
npx @21st-sdk/cli logs my-agent --status active --limit 20
npx @21st-sdk/cli logs my-agent --status active --limit 20 --cursor <nextCursor>

CLI Environment Variables

VariablePurpose
API_KEY_21STOverride the API key used by the CLI