gemini-cli - ✅(Solved) Fix bug: CLI hangs when using custom base URL with invalid model [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#25081Fetched 2026-04-10 03:44:46
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Participants
Timeline (top)
cross-referenced ×2labeled ×2referenced ×1renamed ×1

Error Message

The proxy returns an HTTP 500 error almost immediately, yet the CLI never surfaces the error to the user. An error message such as `Model "nonexistent-model" was not found or is (initial 5 s, cap 30 s, ±30 % jitter). For a persistent proxy error

Root Cause

Two issues compound to produce the hang:

  1. Excessive retriesretryWithBackoff treats HTTP 500 as retriable and retries up to 10 times with exponential back-off (initial 5 s, cap 30 s, ±30 % jitter). For a persistent proxy error this takes ~4 minutes before the retry budget is exhausted.

  2. Unresolvable fallback dialog — After the retries are exhausted, onPersistent429 is called regardless of auth type. This triggers handleFallback, which calls the registered FallbackModelHandler in useQuotaAndFallback. That handler creates a Promise that resolves only when the user dismisses an interactive dialog. When the CLI is running non-interactively (or the dialog does not render correctly for proxy users), the Promise never resolves and the process hangs forever.

    This fallback-on-500 path is intentional for OAuth users (LOGIN_WITH_GOOGLE / COMPUTE_ADC) who may be hitting Google capacity limits. It is not appropriate for API-key users routing through a custom base URL.

Fix Action

Fixed

PR fix notes

PR #25082: fix(core): prevent CLI hang on 500 errors when using custom base URL

Description (problem / solution / changelog)

Summary

When routing through a custom base URL proxy (e.g. LiteLLM) with an invalid model name, the CLI hangs indefinitely instead of showing an error. The proxy returns HTTP 500 immediately, but the CLI retries for ~4 minutes then blocks forever waiting for an interactive fallback dialog that never resolves.

Details

Two issues compound to produce the hang:

1. Excessive retries (~4 min) retryWithBackoff treats HTTP 500 as retriable and retries up to 10 times with exponential back-off (5 s initial, 30 s cap, ±30% jitter).

2. Unresolvable fallback dialog After retries are exhausted, onPersistent429 is called unconditionally. For API-key users this triggers handleFallbackFallbackModelHandler in useQuotaAndFallback, which creates a Promise that resolves only on user interaction with a dialog. The dialog never resolves in practice, causing the process to hang forever.

Fix (packages/core/src/utils/retry.ts) Restrict the onPersistent429 call for HTTP 500 errors to OAuth-based auth types (oauth-personal, compute-default-credentials) only. These users may genuinely be hitting Google capacity limits and benefit from the fallback dialog. API-key users (including custom base URL setups) now have the error propagated immediately after retries.

Additional (packages/core/src/core/) Introduce CustomBaseUrlContentGenerator, which falls back from generateContentStream to generateContent for custom base URL requests. This prevents the SDK's streaming path from hanging when the upstream returns an immediate HTTP error response.

Related Issues

Fixes #25081

How to Validate

GOOGLE_GEMINI_BASE_URL='https://<litellm-host>' \
GEMINI_API_KEY='<key>' \
GEMINI_API_KEY_AUTH_MECHANISM=bearer \
GEMINI_MODEL='nonexistent-model' \
npm run start -- "hello"

## Changed files

- `packages/core/src/core/contentGenerator.test.ts` (modified, +53/-0)
- `packages/core/src/core/contentGenerator.ts` (modified, +22/-3)
- `packages/core/src/core/customBaseUrlContentGenerator.test.ts` (added, +81/-0)
- `packages/core/src/core/customBaseUrlContentGenerator.ts` (added, +112/-0)
- `packages/core/src/utils/retry.ts` (modified, +13/-1)

Code Example

> /about
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                               │
About Gemini CLI│                                                                                                                                                                                                               │
CLI Version                                                             0.37.1Git Commit                                                              3b2d4f100                                                                                                                             │
Model                                                                   Auto (Gemini 3)Sandbox                                                                 no sandbox                                                                                                                            │
OS                                                                      darwin                                                                                                                                │
Auth Method                                                             gemini-api-key                                                                                                                        │
│                                                                                                                                                                                                               │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
RAW_BUFFERClick to expand / collapse

What happened?

When using GOOGLE_GEMINI_BASE_URL to route requests through a custom-endpoint proxy (e.g. LiteLLM) and specifying a model that the proxy does not recognise, the CLI hangs indefinitely.

The proxy returns an HTTP 500 error almost immediately, yet the CLI never surfaces the error to the user.

What did you expect to happen?

An error message such as Model "nonexistent-model" was not found or is invalid. should be shown promptly, similar to the behaviour when an invalid model is passed directly to the Gemini API.

Client information

<details> <summary>Client Information</summary>

Run gemini to enter the interactive CLI, then run the /about command.

> /about
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                               │
│ About Gemini CLI                                                                                                                                                                                              │
│                                                                                                                                                                                                               │
│ CLI Version                                                             0.37.1                                                                                                                                │
│ Git Commit                                                              3b2d4f100                                                                                                                             │
│ Model                                                                   Auto (Gemini 3)                                                                                                                       │
│ Sandbox                                                                 no sandbox                                                                                                                            │
│ OS                                                                      darwin                                                                                                                                │
│ Auth Method                                                             gemini-api-key                                                                                                                        │
│                                                                                                                                                                                                               │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
</details>

Login information

No response

Anything else we need to know?

Root cause

Two issues compound to produce the hang:

  1. Excessive retriesretryWithBackoff treats HTTP 500 as retriable and retries up to 10 times with exponential back-off (initial 5 s, cap 30 s, ±30 % jitter). For a persistent proxy error this takes ~4 minutes before the retry budget is exhausted.

  2. Unresolvable fallback dialog — After the retries are exhausted, onPersistent429 is called regardless of auth type. This triggers handleFallback, which calls the registered FallbackModelHandler in useQuotaAndFallback. That handler creates a Promise that resolves only when the user dismisses an interactive dialog. When the CLI is running non-interactively (or the dialog does not render correctly for proxy users), the Promise never resolves and the process hangs forever.

    This fallback-on-500 path is intentional for OAuth users (LOGIN_WITH_GOOGLE / COMPUTE_ADC) who may be hitting Google capacity limits. It is not appropriate for API-key users routing through a custom base URL.

extent analysis

TL;DR

The CLI hangs indefinitely when a custom-endpoint proxy returns an HTTP 500 error due to excessive retries and an unresolvable fallback dialog, which can be mitigated by modifying the retry logic and fallback handling for API-key users.

Guidance

  • Identify and modify the retryWithBackoff function to treat HTTP 500 errors as non-retriable for API-key users routing through a custom base URL.
  • Review the onPersistent429 function and handleFallback to ensure they are not triggered for API-key users when a custom-endpoint proxy returns an HTTP 500 error.
  • Consider adding a timeout or maximum retry count for API-key users to prevent indefinite hangs.
  • Investigate why the fallback dialog is not rendering correctly for proxy users and address this issue to prevent hangs in interactive modes.

Example

No code snippet is provided as the issue does not include specific code references that can be modified.

Notes

The provided analysis suggests that the issue is specific to API-key users routing through a custom base URL, and the fix should target this use case. The fallback logic for OAuth users should remain intact to handle Google capacity limits.

Recommendation

Apply a workaround by modifying the retry logic and fallback handling for API-key users to prevent indefinite hangs when a custom-endpoint proxy returns an HTTP 500 error. This approach is chosen because the issue is specific to a particular use case and a targeted workaround can address the problem without affecting other users.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING