fix(litellm): fall back to /v1/models if /v1/model/info is forbidden#855
fix(litellm): fall back to /v1/models if /v1/model/info is forbidden#855richard-guan-dev wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesLiteLLM Model Fetching Fallback
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant getLiteLLMModels
participant ModelInfoEndpoint as /v1/model/info
participant ModelsEndpoint as /v1/models
Caller->>getLiteLLMModels: request models
getLiteLLMModels->>ModelInfoEndpoint: GET model info
alt success
ModelInfoEndpoint-->>getLiteLLMModels: model_name/model_info response
getLiteLLMModels->>getLiteLLMModels: parse non-fallback branch
getLiteLLMModels-->>Caller: return model map
else HTTP 403
ModelInfoEndpoint-->>getLiteLLMModels: error
getLiteLLMModels->>ModelsEndpoint: GET fallback models
alt fallback success
ModelsEndpoint-->>getLiteLLMModels: id-based response
getLiteLLMModels->>getLiteLLMModels: parse fallback branch
getLiteLLMModels-->>Caller: return model map
else fallback failure
ModelsEndpoint-->>getLiteLLMModels: error
getLiteLLMModels-->>Caller: reject with original error
end
else non-403 error
ModelInfoEndpoint-->>getLiteLLMModels: error
getLiteLLMModels-->>Caller: reject immediately
end
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/api/providers/fetchers/litellm.ts (1)
35-48: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winFallback triggers on any error and swallows the fallback failure.
Two related concerns in the retry block:
- The
catch (infoError)fires the fallback for any failure (network error, timeout, 500, etc.), not just the 403 this PR targets. A transient/v1/model/infoerror will now silently return degraded models (default capabilities, no pricing) instead of surfacing the failure. Consider gating the fallback on a 403 status.fallbackErroris caught but never logged beforethrow infoError, so when/v1/modelsalso fails there's no visibility into why the fallback failed.♻️ Suggested narrowing + logging
} catch (infoError: any) { + // Only fall back for authorization failures (e.g. virtual keys blocked on /v1/model/info) + if (infoError?.response?.status !== 403) { + throw infoError + } console.warn( `[getLiteLLMModels] Failed to fetch /v1/model/info, attempting fallback to /v1/models:`, infoError.message, ) const fallbackUrlObj = new URL(baseUrl) fallbackUrlObj.pathname = fallbackUrlObj.pathname.replace(/\/+$/, "").replace(/\/+/g, "/") + "/v1/models" const fallbackUrl = fallbackUrlObj.href try { response = await axios.get(fallbackUrl, { headers, timeout: 5000 }) isFallback = true } catch (fallbackError: any) { + console.warn(`[getLiteLLMModels] Fallback to /v1/models also failed:`, fallbackError.message) throw infoError } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/api/providers/fetchers/litellm.ts` around lines 35 - 48, Narrow the LiteLLM fallback in getLiteLLMModels so it only runs for the intended 403 case from /v1/model/info, rather than for every infoError; inspect the error status before building fallbackUrl and calling axios.get. Also, in the fallback catch block, log fallbackError with the existing console.warn/console.error context before rethrowing so failures in /v1/models are visible instead of silently bubbling as infoError.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/api/providers/fetchers/litellm.ts`:
- Around line 35-48: Narrow the LiteLLM fallback in getLiteLLMModels so it only
runs for the intended 403 case from /v1/model/info, rather than for every
infoError; inspect the error status before building fallbackUrl and calling
axios.get. Also, in the fallback catch block, log fallbackError with the
existing console.warn/console.error context before rethrowing so failures in
/v1/models are visible instead of silently bubbling as infoError.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 943030f3-1bcd-4ead-8f07-2ff00e593448
📒 Files selected for processing (2)
src/api/providers/fetchers/__tests__/litellm.spec.tssrc/api/providers/fetchers/litellm.ts
On LiteLLM instances using virtual keys, the metadata endpoint
/v1/model/infois restricted and returns a 403 Forbidden error. This PR adds a fallback mechanism that queries the standard/v1/modelsendpoint instead to list available models, parsing the simpler payload correctly.Summary by CodeRabbit