Setup
Option A: Website (Manual)
Get your API key
Sign up at api.mathematicalcompany.com and copy your API key.
Keys start with
hz_live_.Set the environment variable
Add this to your shell profile (Then reload your shell or run
~/.zshrc, ~/.bashrc, etc.):source ~/.zshrc.Option B: Programmatic (Agentic)
Create an account and generate an SDK key entirely from the command line or through an AI agent. No browser required.Run setup
Pass your password via the This will:
HORIZON_PASSWORD environment variable to avoid shell history exposure:- Try to log in (if you already have an account)
- Sign up if the account does not exist
- Generate a new SDK key
- Save the encrypted key to
~/.horizon/credentials.json
MCP / AI Agent Setup
AI agents using the MCP server or OpenClaw skill can call the auth tools directly:| Tool | Action | Description |
|---|---|---|
account | setup | Create account and generate SDK key (full flow) |
account | login | Login to existing account and generate new key |
account | key_status | Check if credentials are configured |
HORIZON_PASSWORD, and calls account(action="setup", params="{\"email\": \"...\"}"). The key is saved encrypted to disk and never returned in full in tool responses (only the prefix is shown).
Python API
Security
- Passwords: Always use the
HORIZON_PASSWORDenv var instead of passing passwords as CLI arguments. CLI arguments are visible in shell history and process listings. - Key storage: Credentials are encrypted at rest using a machine-derived key (hostname + username). The plaintext key is never written to disk.
- Key exposure: Tool responses only include the key prefix, never the full key.
- Rate limiting: Client-side rate limiting caps auth attempts to 5 per 60 seconds.
How It Works
- Startup only - validation happens once when
Engineis created (insidehz.run()). After that, no network calls are made during trading. - Local cache - a successful validation is cached at
~/.horizon/license.jsonfor 72 hours. The raw key is never stored, only a SHA-256 hash. - Offline grace period - if the network is unavailable but a valid cache exists for your key, the SDK allows startup. No internet dependency during cached periods.
- Compiled in Rust - the validation logic is in the compiled binary, not in bypassable Python code.
Configuration
There are two ways to provide your API key:Environment Variable (Recommended)
Explicit Parameter
You can pass the key directly in code - useful for notebooks, testing, or when you don’t want to set environment variables. Withhz.run():
Engine() directly:
Resolution Order
| Priority | Source |
|---|---|
| 1 | api_key param in hz.run() / api_key param in Engine() |
| 2 | HORIZON_API_KEY environment variable |
| 3 | ~/.horizon/credentials.json (saved by programmatic setup) |