Create or improve a lightweight failover layer for AI APIs.
Build systems that:
Use the detailed rules below and the bundled scripts instead of re-inventing routing logic each time.
Use these normalized categories:
AUTH_ERRORBAD_REQUESTRATE_LIMITTIMEOUTSERVER_ERRORNETWORK_ERRORMODEL_UNAVAILABLEQUOTA_EXCEEDEDUNKNOWN_TRANSIENTAUTH_ERROR, BAD_REQUEST: fail fast; do not retry other providers unless config explicitly maps to another credential set.RATE_LIMIT: short backoff, then fallback.TIMEOUT, SERVER_ERROR, NETWORK_ERROR, MODEL_UNAVAILABLE, UNKNOWN_TRANSIENT: retry briefly, then fallback.QUOTA_EXCEEDED: mark provider unavailable for a longer cooldown and fallback immediately.Start with:
3 consecutive transient failures60-180s1 probe1-2 successful probesKeep policy in config, not hard-coded logic.
Recommended shape:
Use this skill to discover the environment, generate a production-ish config, run a local HTTP failover proxy, and verify health.
Do not claim full autonomous takeover unless the environment-specific integration is actually completed.
Read these only when needed:
references/config-example.yaml for a compact policy examplereferences/config-realworld-example.yaml for a more practical multi-provider templatereferences/config-production.yaml for a ready-to-edit production templatereferences/test-scenarios.md for failure-injection and validation casesreferences/realworld-notes.md for local proxy deployment and environment-variable setupreferences/api-failover.service for a user-systemd service examplescripts/discover_env.pyInspect the current environment.
scripts/generate_config.pyGenerate a production-ish YAML config from simple defaults.
scripts/failover_proxy.pyRun a minimal CLI failover call path.
scripts/http_proxy.pyExpose a single local OpenAI-compatible entrypoint.
Endpoints:
POST /v1/chat/completionsGET /healthOptional request header:
X-Failover-Profile: cheap|default|critical|local-firstscripts/selfcheck.pyValidate that the local proxy is reachable and can process a minimal chat request.
scripts/bootstrap_failover.pyRun the semi-automatic bootstrap flow:
Example:
python3 scripts/bootstrap_failover.py \
--default-model custom-ai-td-ee/gpt-5.4 \
--start-proxy
Keep these scripts small and inspectable. Extend them instead of turning SKILL.md into code-heavy instructions.
共 1 个版本