Skip to content

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
usestrix:mainfrom
Suraj-kummar:fix/issue-1095-duplicate-api-key
Open

fix(config): don't set litellm.api_key global when LLM_API_BASE is co…#1102
Suraj-kummar wants to merge 1 commit into
usestrix:mainfrom
Suraj-kummar:fix/issue-1095-duplicate-api-key

Conversation

@Suraj-kummar

Copy link
Copy Markdown

…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

…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
@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The 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 LitellmModel.

  • Adds a custom-base guard around the LiteLLM global API-key assignment.
  • Preserves the existing SDK default-key and provider-environment mirroring paths.
  • Adds regression coverage for Anthropic-prefixed and OpenAI-prefixed custom-base configurations, plus the standard no-custom-base behavior.

Confidence Score: 5/5

The 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

Filename Overview
strix/config/models.py Skips the LiteLLM global API-key default for custom API bases while retaining the existing provider-specific and OpenAI SDK key configuration.
tests/test_llm_api_base_no_duplicate_key.py Adds isolated regression tests covering custom-base behavior for Anthropic and OpenAI prefixes and the unchanged direct-provider behavior.

Reviews (1): Last reviewed commit: "fix(config): don't set litellm.api_key g..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLM CONNECTION FAILED — duplicate api_key keyword argument when LLM_API_BASE is set to a custom endpoint

1 participant