Nansen CLI

Overview

The Nansen CLI (nansen-cli) is a command-line interface for the Nansen API. All output is structured JSON, making it ideal for AI agents, scripts, and automation pipelines.

npm install -g nansen-cli

Or run without installing:

npx nansen-cli help

Source code: github.com/nansen-ai/nansen-cliarrow-up-right

Authentication

The CLI uses the same API key as the REST API. Two options, in priority order:

Environment variable (recommended for agents and CI):

export NANSEN_API_KEY=your-api-key

Interactive login (persistent):

nansen login

Verify it works:

nansen schema | head -1

schema is free and requires no API key -- if you get JSON back, the CLI is installed correctly.

Quick Start

Schema Discovery

The CLI is fully self-documenting via nansen schema. This requires no API key and returns a machine-readable JSON reference of all commands, options, return fields, and supported chains.

Example: query supported chains:

Agents should use nansen schema as the source of truth for available commands and options.

Output Format

All responses use a consistent JSON envelope:

Errors include a machine-readable code:

Key error codes: UNAUTHORIZED, CREDITS_EXHAUSTED, RATE_LIMITED, INVALID_ADDRESS, UNSUPPORTED_FILTER. See Error Handling for the full list.

Tips for AI Agents

Use schema for self-discovery. Agents should call nansen schema at the start of a session to learn available commands, options, and supported chains -- it costs zero credits.

Use --fields to reduce response size. Large JSON responses waste agent context tokens.

Use --stream for large result sets. Processes results line-by-line instead of buffering the entire response.

Budget credits carefully. Most calls cost 1 credit. schema and help are free. If you get CREDITS_EXHAUSTED, stop all calls immediately.

Last updated

Was this helpful?