Skip to content

feat(transport): automatic API key fallback for gemini-cli quota exhaustion#393

Merged
RyderFreeman4Logos merged 1 commit intomainfrom
feat/gemini-api-key-fallback
Mar 10, 2026
Merged

feat(transport): automatic API key fallback for gemini-cli quota exhaustion#393
RyderFreeman4Logos merged 1 commit intomainfrom
feat/gemini-api-key-fallback

Conversation

@RyderFreeman4Logos
Copy link
Owner

Summary

  • Add api_key field to GlobalToolConfig for structured fallback credential storage
  • When gemini-cli OAuth quota is exhausted and all 3 model-switch retries fail, automatically inject GEMINI_API_KEY from config and retry once
  • Guard fallback injection to gemini-cli tool exclusively (not injected for other tools)
  • Mask api_key in redacted_for_display() to prevent credential leakage in diagnostics

Design

OAuth-first, API-key-fallback: The transport retry loop tries OAuth auth with 3 different models first. Only after all fail with quota/429 errors does it check for a configured api_key and attempt one final run with GEMINI_API_KEY injected. When quota recovers, OAuth resumes automatically with no config change needed.

Pipeline: [tools.gemini-cli].api_key_CSA_API_KEY_FALLBACK in extra_env → inject_api_key_fallback() promotes to GEMINI_API_KEY → gemini-cli uses it.

Test plan

  • Unit test: inject_api_key_fallback promotes key and cleans internal signal
  • Unit test: returns None when no fallback key configured
  • Integration test: execute_in fallback path after all retries exhausted
  • Integration test: Transport::execute fallback path after all retries exhausted
  • All 2465 unit + 16 e2e tests pass
  • just pre-commit passes (fmt, clippy, deny, test, monolith check)

…exhaustion

When gemini-cli OAuth quota is exhausted and all model-switch retries fail,
automatically fall back to the configured api_key from [tools.gemini-cli]
in global config. This preserves OAuth-first priority while enabling seamless
recovery without manual intervention.

- Add api_key field to GlobalToolConfig with redaction in diagnostic output
- Inject _CSA_API_KEY_FALLBACK via extra_env pipeline (gemini-cli only)
- Transport retry loop: after 3 model retries, attempt one final run with
  GEMINI_API_KEY injected from fallback
- Guard fallback injection to gemini-cli tool exclusively
- Add unit + integration tests for fallback promotion and both execute paths
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@RyderFreeman4Logos
Copy link
Owner Author

Merge Rationale

Cloud bot: disabled (pr_review.cloud_bot = false, codex quota exhausted)

Local review coverage:

  1. Per-commit review: csa review --diff via claude-code — PASS (session 01KKB9TNDZ3)
  2. Cumulative review: csa review --branch main via claude-code — PASS (session 01KKBAA0QDF)

Review findings addressed:

  • P1 (api_key redaction): Fixed — redacted_for_display() now masks api_key fields
  • P2 (gemini-only guard): Fixed — _CSA_API_KEY_FALLBACK injection gated to gemini-cli tool only
  • P3 (test gap): Fixed — added test_execute_falls_back_to_api_key_after_all_retries_exhausted

Test results: 2465 unit + 16 e2e tests pass. just pre-commit clean.

@RyderFreeman4Logos RyderFreeman4Logos merged commit fd4cf1a into main Mar 10, 2026
4 of 6 checks passed
@RyderFreeman4Logos RyderFreeman4Logos deleted the feat/gemini-api-key-fallback branch March 10, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant