Setup
Option A: Website (Manual)
1
Get your API key
Sign up at api.mathematicalcompany.com and copy your API key.
Keys start with
hz_sdk_.2
Set the environment variable
Add this to your shell profile (Then reload your shell or run
~/.zshrc, ~/.bashrc, etc.):source ~/.zshrc.3
Run your strategy
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.1
Install the SDK
2
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
3
Run your strategy
The engine auto-loads the key from Or set the env var explicitly:
~/.horizon/credentials.json:MCP / AI Agent Setup
AI agents using the MCP server or OpenClaw skill can call the auth tools directly:
The agent asks the user for their email, sets
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: