CLI
The official command-line interface (@spyglasshq/cli on npm, spyglass-so/spyglass-cli on GitHub) runs every Spyglass API endpoint as a spyglass command. It ships as a single native binary for macOS, Linux, and Windows, and it is generated from the same OpenAPI spec as the SDKs, so it stays in sync with the API.
Installation
Check the install:
Authentication
- Get an API key from Settings → API in the dashboard.
- Export it as
SPYGLASS_API_KEY:
To keep the key out of your shell profile, store it in the OS keychain instead. The API uses a bearer token and the CLI has no browser login, so pass --with-token and paste the key when stdin waits:
spyglass auth login on its own exits with No login flow declared for scheme bearerAuth. If the key is already in the environment, spyglass auth login --with-token --from-env copies it into the keychain without a paste.
The CLI also reads SPYGLASS_API_KEY from a .env file in the working directory. In CI, load the key from a secret.
Quick start
Run spyglass --help for the full command tree, and spyglass <command> <subcommand> --help for every flag on one operation.
Commands
Each command costs the same as the endpoint it calls. See Billing.
Passing parameters
Every request field is a kebab-case flag. accountId becomes --account-id, and igUsername becomes --ig-username. Repeat a flag for array fields, or pass a JSON array:
Two fields have different flag names, because --query and --format are global CLI flags:
For endpoints with a request body, you can also send the whole body as JSON, or pipe it from stdin with --json -:
Output
Output is a table in a terminal and JSON when piped, so scripts and agents get JSON without extra flags. Set it explicitly with --format json|table|yaml|csv|jsonl|raw|http, or with the SPYGLASS_OUTPUT environment variable.
Use --query to filter the response with a JMESPath expression before it prints. --format raw prints the response unchanged and ignores --query.
Examples
Fetch an account’s posts live
spyglass account posts doesn’t need the account to be indexed. Send exactly one of --ig-username, --tiktok-username, or --facebook-ad-library-id. A call usually takes 10–30 seconds.
Creative insights, campaigns, and landing pages
--id accepts an account id, a website, or an Instagram or TikTok handle:
Index a new account and wait for it
Indexing is free. Poll index-status until status is ready:
Check remaining credits
Using the CLI from coding agents
The CLI is designed for agents such as Cursor, Claude Code, and Codex:
- Output is JSON whenever it isn’t a terminal.
--dry-runprints the exact HTTP request without sending it or spending credits.spyglass --help --format json(or--schema) prints a machine-readable catalog of every command and flag.spyglass generate-skillswritesSKILL.mdfiles that teach an agent the commands. Point--output-dirat your agent’s skills folder:
Agents that support MCP can also use the hosted MCP server without an API key.
Errors and retries
Errors print to stderr as JSON with code, reason, and message, and the process exits non-zero. The API’s error codes are listed in Errors.
The CLI retries network errors and retryable statuses automatically. Use --retries <N> to change the count, or --no-retry to turn retries off. Add --debug to print the full HTTP request and response to stderr.
Shell completion
Upgrading
Rerun the command you installed with, for example npm install -g @spyglasshq/cli@latest.