Skip to main content
Repair and provision a gateway config from Python — no shell-out, no interactive wizard, and a typed result you can assert on.

Quick Start

1

Repair a broken config

2

Provision a config from scratch

3

Detect without repairing


How It Works

Both entry points share the detect → repair → re-validate lifecycle behind praisonai gateway doctor --fix.

When to use which


API Reference

Three symbols make up the whole public surface.

repair_gateway_config

repair_gateway_config(config_path, *, fix=False, dry_run=False) -> GatewayRepairResult Runs the same detect → repair → re-validate lifecycle as praisonai gateway doctor --fix: forward-migrate an out-of-date config_version and mint/persist a strong gateway.auth_token when the configured one is weak or missing.
For a CI gate that rejects misspelled gateway/channel keys outright, MultiChannelGatewayConfig.from_dict(data, strict=True) raises ConfigValidationError on an unknown key — a direct Python entry point that complements this detect-only repair. See Strict unknown-key validation.

provision_gateway_config

provision_gateway_config(*, platform, token, agents=None, config_path=None) -> Path
provision_gateway_config is fail-closed: an unsupported platform or an empty token raises ValueError and writes nothing, rather than producing a config the gateway would boot degraded.
As of PR #5611, the generated bot.yaml writes the detected provider’s model into agent.model (last-resort fallback: gpt-4o-mini). Pass an explicit model=... to pin the agent to a specific one. See Provider auto-detection.

GatewayRepairResult

@dataclass(frozen=True) — the closed result shape returned by repair_gateway_config. .to_dict() returns a shallow JSON-safe copy of all four fields.

Precedence & Fallbacks

The auth-token repair interacts with ${ENV} references and explicit YAML tokens as follows.

CLI parity

The Python API, CLI, and YAML surfaces run the same helpers.

Common Patterns

CI-driven per-tenant provisioning

Post-deploy self-healing check

Testing the fixed gateway in pytest

Explicit path vs default location


Best Practices

Run without fix=True, review remaining_degraded_owners, then re-run with fix=True. A detect-only pass never writes to disk.
Config-version drift and weak tokens are silent until you check. Wire repair_gateway_config(path, fix=False) into your post-deploy smoke test.
provision_gateway_config(token=...) persists the credential to ~/.praisonai/.env (0600). Pass a ${VAR} reference in your YAML so the secret stays out of source control.
Both surfaces run the same helpers in admin.py — a repair from either is identical. Use the CLI interactively, the Python API in CI and tests.
An unsupported platform or empty token refuses to write, preventing a “starts degraded” outcome. Do not catch and ignore it.

Gateway CLI

The wrapping gateway doctor commands.

Bot Onboarding

The interactive wizard — sibling of provision_gateway_config.

Bind-Aware Auth

Weak-secret guard context.

Config Migration

Config-version migration context.