fix: url construction for trailing v1 base urls#26037
fix: url construction for trailing v1 base urls#26037rohan-shettyy wants to merge 2 commits intoBerriAI:litellm_internal_stagingfrom
Conversation
Greptile SummaryThis PR fixes a URL construction bug in Confidence Score: 5/5Safe to merge — targeted one-method fix with comprehensive mock-based test coverage. The change is isolated to a single method, the logic is straightforward and correct, all test cases pass and are properly mocked (no live network calls), and no existing tests were modified. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/openai/chat/gpt_transformation.py | Added trailing-slash strip + /v1-awareness to get_models() URL construction; change is minimal and correct. |
| tests/litellm/llms/test_openai_get_models_url.py | New test file covering nine URL scenarios for get_models(); all calls are properly mocked with no real network requests. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["get_models(api_key, api_base)"] --> B{api_base is None?}
B -->|Yes| C["api_base = 'https://api.openai.com'"]
B -->|No| D["use provided api_base"]
C --> E["strip trailing '/'"]
D --> E
E --> F{ends with '/v1'?}
F -->|Yes| G["url = api_base + '/models'"]
F -->|No| H["url = api_base + '/v1/models'"]
G --> I["GET url with Bearer token"]
H --> I
I --> J{status 200?}
J -->|Yes| K["return model IDs"]
J -->|No| L["raise Exception"]
Reviews (2): Last reviewed commit: "add tests for edge cases" | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Relevant issues
Fixes #26009
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
Before fix: test failing
After fix: tests passing
Type
🐛 Bug Fix
Changes
Fix: Preserves sub-paths in api_base and avoids duplicate /v1 segments when calling get_models() in OpenAIGPTConfig. Fixes #26009.
Tests: Adds unit tests for get_models() URL construction across multiple api_base formats.