---
title: "Horizon Configuration"
description: "Environment variables for Horizon exchanges, logging, and database configuration."
icon: "sliders"
---

Horizon reads credentials and configuration from environment variables as a fallback when not passed explicitly to constructors.

## Horizon API Key

| Variable | Description |
|----------|-------------|
| `HORIZON_API_KEY` | Your Horizon SDK API key (required) |

```bash
export HORIZON_API_KEY="hz_live_abc123..."
```

Get your key at [horizon.mathematicalcompany.com](https://horizon.mathematicalcompany.com). See the [Authentication](/authentication) page for details.

## Polymarket

| Variable | Description |
|----------|-------------|
| `POLYMARKET_PRIVATE_KEY` | Ethereum private key (hex, with or without `0x` prefix) |
| `POLYMARKET_API_KEY` | CLOB API key |
| `POLYMARKET_API_SECRET` | CLOB API secret |
| `POLYMARKET_API_PASSPHRASE` | CLOB API passphrase |

```bash
export POLYMARKET_PRIVATE_KEY="0x..."
export POLYMARKET_API_KEY="..."
export POLYMARKET_API_SECRET="..."
export POLYMARKET_API_PASSPHRASE="..."
```

```python
hz.Polymarket()  # reads from env automatically
```

## Kalshi

| Variable | Description |
|----------|-------------|
| `KALSHI_EMAIL` | Kalshi account email |
| `KALSHI_PASSWORD` | Kalshi account password |
| `KALSHI_API_KEY` | Kalshi API key |
| `KALSHI_API_URL` | Kalshi API base URL (override for demo/staging) |

```bash
export KALSHI_API_KEY="..."
# or
export KALSHI_EMAIL="..."
export KALSHI_PASSWORD="..."
```

```python
hz.Kalshi()  # reads from env automatically
```

## Database

| Variable | Description | Default |
|----------|-------------|---------|
| `HORIZON_DB` | SQLite database path | `./{strategy_name}.db` |

```bash
export HORIZON_DB="/data/horizon.db"
```

## Logging

| Variable | Description | Default |
|----------|-------------|---------|
| `HORIZON_LOG` | Rust tracing filter level | `warn` |

Valid levels: `debug`, `info`, `warn`, `error`

### Python Logging

Horizon uses Python's `logging` module for the Python layer:

```python
import logging
logging.basicConfig(level=logging.DEBUG)
```

### Rust Logging

Set the Rust tracing level via environment variable:

```bash
HORIZON_LOG=debug python my_strategy.py
```

### CLI Log Level

The `--log-level` flag sets both Python logging and the `HORIZON_LOG` environment variable:

```bash
python -m horizon run strategy.py --log-level=debug
```

## Credential Resolution Order

Both `Polymarket` and `Kalshi` resolve credentials in this order:

<Steps>
  <Step title="Explicit constructor arguments">
    ```python
    hz.Polymarket(private_key="0x...", api_key="...")
    ```
  </Step>
  <Step title="Environment variables">
    ```python
    hz.Polymarket()  # reads POLYMARKET_PRIVATE_KEY, etc.
    ```
  </Step>
</Steps>

Explicit arguments always take priority over environment variables.
