# Configuration

Configuration file: `pi-gateway.jsonc` (JSONC format)

## Gateway Settings

```jsonc
{
  "gateway": {
    "port": 52134,        // HTTP/WebSocket port
    "bind": "loopback",   // "loopback" | "lan" | "auto"
    "auth": {
      "mode": "token",    // "off" | "token" | "password"
      "token": "your-secret-token"
    }
  }
}
```

## Agent Settings

```jsonc
{
  "agent": {
    "model": "claude-sonnet-4",
    "modelFailover": {
      "primary": "claude-sonnet-4",
      "fallbacks": ["gpt-4o", "gemini-pro"],
      "maxRetries": 2,
      "cooldownMs": 60000
    },
    "pool": {
      "min": 1,
      "max": 4
    }
  }
}
```

## Channel Settings

### Telegram

```jsonc
{
  "channels": {
    "telegram": {
      "enabled": true,
      "botToken": "${TELEGRAM_BOT_TOKEN}",
      "dmPolicy": "pairing",  // "pairing" | "allowlist" | "open" | "disabled"
      "accounts": {
        "default": { "enabled": true }
      }
    }
  }
}
```

### Discord

```jsonc
{
  "channels": {
    "discord": {
      "enabled": true,
      "token": "${DISCORD_TOKEN}"
    }
  }
}
```

## Security Policies

| Policy | Description |
|--------|-------------|
| `pairing` | Unknown users get pairing code, admin approves |
| `allowlist` | Only configured user IDs can interact |
| `open` | Anyone can interact |
| `disabled` | Block all DMs |

## Cron Jobs

```jsonc
{
  "cron": {
    "enabled": true,
    "jobs": [
      {
        "id": "daily-report",
        "schedule": { "kind": "cron", "expr": "0 9 * * *" },
        "task": "Generate daily report",
        "delivery": "announce"
      }
    ]
  }
}
```

## Environment Variables

Use `${VAR_NAME}` syntax to reference environment variables:

```jsonc
{
  "channels": {
    "telegram": {
      "botToken": "${TELEGRAM_BOT_TOKEN}"
    }
  }
}
```

See [pi-gateway.jsonc.example](https://github.com/openclaw/pi-gateway/blob/main/pi-gateway.jsonc.example) for full configuration options.
