AI Trace Viewer uses a flexible configuration system that supports:
Configuration priority (highest to lowest):
AITRACE_)~/.config/aitrace/config.yaml or config.toml)All configuration and data files are stored in:
~/.config/aitrace/
├── config.yaml # Active YAML config (optional)
├── config.toml # Active TOML config (optional)
├── config.yaml.example # Example YAML config
├── config.toml.example # Example TOML config
└── logs.db # SQLite database (+ .db-shm, .db-wal)
The directory is automatically created when you first run the server.
| Option | CLI Flag | Environment Variable | Default | Description |
|---|---|---|---|---|
| Host | --host |
AITRACE_HOST |
0.0.0.0 |
Host to bind the server to |
| Port | --port |
AITRACE_PORT |
8000 |
Port to bind the server to |
| Workers | --workers |
AITRACE_WORKERS |
1 |
Number of worker processes |
| Option | CLI Flag | Environment Variable | Default | Description |
|---|---|---|---|---|
| Database Path | --db-path |
AITRACE_DB_PATH |
~/.config/aitrace/logs.db |
Path to SQLite database file |
| Option | CLI Flag | Environment Variable | Default | Description |
|---|---|---|---|---|
| Auto-reload | --reload |
AITRACE_RELOAD |
false |
Enable auto-reload for development |
| Log Level | --log-level |
AITRACE_LOG_LEVEL |
info |
Logging level (critical/error/warning/info/debug) |
| Access Log | --access-log |
AITRACE_ACCESS_LOG |
false |
Enable HTTP access logging |
| Option | CLI Flag | Environment Variable | Default | Description |
|---|---|---|---|---|
| Config File | --config / -c |
N/A | ~/.config/aitrace/config.yaml |
Path to custom config file |
Create a config file:
# Copy example to active config
cp ~/.config/aitrace/config.yaml.example ~/.config/aitrace/config.yaml
# Edit the config
vim ~/.config/aitrace/config.yaml
Example config.yaml:
# Server configuration
host: 0.0.0.0
port: 8000
# Database configuration
db-path: ~/.config/aitrace/logs.db
# Development options
reload: false
log-level: info
access-log: false
# Worker processes
workers: 1
Run the server (uses config file automatically):
python -m aitrace
# or
aitrace
# Set environment variables
export AITRACE_HOST=localhost
export AITRACE_PORT=9000
export AITRACE_LOG_LEVEL=debug
export AITRACE_ACCESS_LOG=true
# Run the server
python -m aitrace
# Override specific settings
python -m aitrace --host localhost --port 9000 --log-level debug
# Use custom database location
python -m aitrace --db-path /tmp/my-traces.db
# Development mode with auto-reload
python -m aitrace --reload --log-level debug --access-log
# Use a custom config file location
python -m aitrace --config /path/to/my-config.yaml
# Or with environment variable
export AITRACE_CONFIG=/path/to/my-config.yaml
python -m aitrace
Config files, environment variables, and CLI args can be combined. The priority order ensures the most specific setting wins:
# config.yaml has port: 8000
# Environment has AITRACE_PORT=9000
# CLI has --port 10000
python -m aitrace --port 10000
# Result: Server runs on port 10000 (CLI wins)
# ~/.config/aitrace/config.yaml
host: 0.0.0.0
port: 8000
db-path: /var/lib/aitrace/logs.db
log-level: warning
access-log: false
workers: 1 # Keep at 1 for SQLite
# ~/.config/aitrace/config.yaml
host: localhost
port: 8000
db-path: ~/.config/aitrace/dev.db
reload: true
log-level: debug
access-log: true
workers: 1
If you prefer TOML, create config.toml instead:
# ~/.config/aitrace/config.toml
host = "0.0.0.0"
port = 8000
db-path = "~/.config/aitrace/logs.db"
reload = false
log-level = "info"
access-log = false
workers = 1
You can also access configuration in your Python code:
from aitrace import get_config_dir, get_data_dir, load_config
# Get config directory
config_dir = get_config_dir()
print(f"Config directory: {config_dir}")
# Get data directory (same as config for now)
data_dir = get_data_dir()
print(f"Data directory: {data_dir}")
# Load configuration programmatically
config = load_config()
print(f"Server will run on {config.host}:{config.port}")
print(f"Database location: {config.db_path}")
config.yamlIf you see messages about missing config files:
# Initialize default config files
python -m aitrace
# This creates the example files automatically
# Then copy and edit
cp ~/.config/aitrace/config.yaml.example ~/.config/aitrace/config.yaml
If you get “database is locked” errors:
workers: 1 in your config.db-shm, .db-wal)If you can’t write to ~/.config/aitrace:
# Check/fix permissions
mkdir -p ~/.config/aitrace
chmod 755 ~/.config/aitrace
# Or use a custom location
python -m aitrace --db-path /tmp/logs.db