fix: sync base_url and api_base for litellm multi-provider routing#5140
Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Open
fix: sync base_url and api_base for litellm multi-provider routing#5140devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
When LLM(base_url=...) is used without api_base, litellm does not receive the custom endpoint because it reads api_base (not base_url). This causes requests to fall back to api.openai.com, breaking multi-provider setups (e.g. Scaleway + Nebius). The fix syncs base_url and api_base in LLM.__init__: - If only base_url is provided, api_base is set to match - If only api_base is provided, base_url is set to match - If both are provided, both keep their explicit values Closes #5139 Co-Authored-By: João <joao@crewai.com>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: João <joao@crewai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5139. When
LLM(base_url=...)is used without explicitly settingapi_base, litellm never receives the custom endpoint because it readsapi_base, notbase_url. This causes requests to fall back toapi.openai.com, breaking multi-provider setups (e.g. Scaleway + Nebius with different API keys and endpoints).The fix adds a 4-line sync in
LLM.__init__so that whichever parameter the caller provides, both fields are populated:base_urlprovided →api_baseis set to matchapi_baseprovided →base_urlis set to matchNoneThis ensures
_prepare_completion_paramsalways includesapi_basein the kwargs passed tolitellm.completion().Review & Testing Checklist for Human
_prepare_completion_params: This fix works because_prepare_completion_paramspassesapi_base/api_keytolitellm.completion(). If any code path (e.g. agent reasoning loops, tool selection) calls litellm without going through_prepare_completion_params, those calls would still lack the custom endpoint. Grep for directlitellm.completion/litellm.acompletioncalls outside this path.LLMinstances with differentbase_url/api_keyvalues, assign them to different agents in the same crew, and run a task. Confirm each agent's requests go to the correct endpoint (e.g. via debug logging or network inspection).LLM.__init__(the litellm fallback path). Native providers (OpenAI, Anthropic, Gemini, etc.) use their own__init__viaBaseLLM. Verify no regressions forLLM(model="gpt-4o")orLLM(model="anthropic/claude-3-sonnet").Notes
litellm.completion/litellm.acompletion. This PR intentionally does not implement that — the simpler param-syncing fix should be sufficient since_prepare_completion_paramsalready passesapi_base/api_keyto every litellm call._prepare_completion_params, multi-provider independence,litellm.completionmock verification, and copy/deepcopy preservation.tests (3.13)CI job was cancelled (infrastructure, not a failure); all other required checks (lint, type-checker, tests on 3.10/3.11/3.12) passed.Link to Devin session: https://app.devin.ai/sessions/3ccb7f0ac5ba4e0c95dc59b9556576a3