Authentication
The Legend API uses bearer token authentication. Every request must include a query key or JWT in theAuthorization header.
Three auth methods
| Method | Best for | Duration |
|---|---|---|
| Query Key | Programmatic access, CI/CD, SDKs | Until revoked |
| OAuth JWT | CLI, MCP agents, browser-based flows | 30 days |
| OAuth (MCP) | Claude Code, Cursor (remote MCP server) | 30 days |
Query keys
Get a query key from dashboard.legend.xyz under Settings > API Keys:OAuth login (CLI)
Thelegend-cli can authenticate via Google SSO:
Making requests
Include your query key or JWT as a bearer token:Two layers of auth
The Legend API separates API access from fund authorization:| Layer | What it does | Who has it |
|---|---|---|
| Query key | Authenticates API requests — read data, create accounts, create plans | Your server |
| Signer key | Authorizes on-chain transactions — earn, withdraw, transfer | You or your end-user |
Key rotation
You can have multiple active query keys for the same Prime Account. To rotate:- Create a new query key
- Update your application to use the new key
- Revoke the old key
Security best practices
- Store query keys in environment variables or a secrets manager
- Use separate keys for production and development
- Rotate keys periodically and immediately if compromised
- Query keys grant access to all sub-accounts under your Prime Account — scope access at the application level if needed