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 behindpraisonai gateway doctor --fix.
When to use which
API Reference
Four 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.
provision_gateway_config
provision_gateway_config(*, platform, token, agents=None, config_path=None) -> Path
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.edit_gateway_channel
edit_gateway_channel(config_path, name, settings=None, *, remove=False) -> dict
Add, update, or remove one channels: entry in place. Other channels and top-level keys are untouched, and the edited document is validated against GatewayConfigSchema before the atomic write, so an invalid edit is rejected rather than persisted.
Returns the resulting channel block (
{} when remove=True). Raises FileNotFoundError, KeyError (removing a missing channel), or ValueError (unknown platform, bad types, or no enabled channel left).
See Gateway Channel Lifecycle for the matching CLI, legacy-config migration, and concurrent-edit safety.
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
🧪 Verify with the detect pass first
🧪 Verify with the detect pass first
Run without
fix=True, review remaining_degraded_owners, then re-run with fix=True. A detect-only pass never writes to disk.🔁 Re-run after every deploy
🔁 Re-run after every deploy
Config-version drift and weak tokens are silent until you check. Wire
repair_gateway_config(path, fix=False) into your post-deploy smoke test.🔒 Never commit the token
🔒 Never commit the token
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.🧭 Keep the CLI and Python in sync
🧭 Keep the CLI and Python in sync
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.🛑 Treat ValueError as fail-closed
🛑 Treat ValueError as fail-closed
An unsupported
platform or empty token refuses to write, preventing a “starts degraded” outcome. Do not catch and ignore it.Related
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.
Gateway Channel Lifecycle
Add, update, disable, or remove one channel — CLI and Python.

