fix(config): don't set litellm.api_key global when LLM_API_BASE is co… - #1102
Open
Suraj-kummar wants to merge 1 commit into
Open
fix(config): don't set litellm.api_key global when LLM_API_BASE is co…#1102Suraj-kummar wants to merge 1 commit into
Suraj-kummar wants to merge 1 commit into
Conversation
…nfigured (usestrix#1095) When LLM_API_BASE is set, the model routes through openai-agents' LitellmModel which always forwards api_key=self.api_key (None by default) as an explicit kwarg on every litellm.acompletion() call. Setting litellm.api_key as a module-level global on top of that caused: TypeError: acompletion() got multiple values for keyword argument 'api_key' (anthropic/ prefix path) TypeError: AsyncCompletions.create() got an unexpected keyword argument 'api_key' (openai/ prefix path) Fix: guard _configure_litellm_default('api_key', ...) behind 'if not llm.api_base'. The key still reaches the provider via _mirror_api_key_to_provider_env (sets the provider-specific *_API_KEY env var e.g. ANTHROPIC_API_KEY) and set_default_openai_key, so skipping the module-level global is safe. Fixes usestrix#1095
Contributor
Greptile SummaryThe PR avoids setting LiteLLM’s module-level API key when a custom LLM API base is configured, preventing it from colliding with the explicit key argument supplied by
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking issues identified. The custom-base branch removes the conflicting LiteLLM global while retaining the existing key-delivery paths, and the added tests cover both affected prefix routes and the unchanged no-base route. Important Files Changed
Reviews (1): Last reviewed commit: "fix(config): don't set litellm.api_key g..." | Re-trigger Greptile |
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.
…nfigured (#1095)
When LLM_API_BASE is set, the model routes through openai-agents' LitellmModel which always forwards api_key=self.api_key (None by default) as an explicit kwarg on every litellm.acompletion() call. Setting litellm.api_key as a module-level global on top of that caused:
TypeError: acompletion() got multiple values for keyword argument
'api_key' (anthropic/ prefix path)
TypeError: AsyncCompletions.create() got an unexpected keyword
argument 'api_key' (openai/ prefix path)
Fix: guard _configure_litellm_default('api_key', ...) behind 'if not llm.api_base'. The key still reaches the provider via _mirror_api_key_to_provider_env (sets the provider-specific *_API_KEY env var e.g. ANTHROPIC_API_KEY) and set_default_openai_key, so skipping the module-level global is safe.
Fixes #1095