Skip to content

fix: resolve config dict api_key not being unpacked in OpenAI-based providers#72

Merged
lfnovo merged 1 commit intomainfrom
fix/config-dict-api-key-issue-68
Jan 24, 2026
Merged

fix: resolve config dict api_key not being unpacked in OpenAI-based providers#72
lfnovo merged 1 commit intomainfrom
fix/config-dict-api-key-issue-68

Conversation

@lfnovo
Copy link
Owner

@lfnovo lfnovo commented Jan 24, 2026

Summary

Root Cause

Providers that inherit from OpenAI-compatible parent classes were checking for api_key before the config dict was unpacked by the base class's __post_init__. Additionally, when calling super().__post_init__() first, the parent OpenAI class would set its own defaults before the child provider could set its own.

Fix

For providers that inherit from OpenAI-compatible parent classes, manually extract api_key and base_url from the config dict before setting provider-specific defaults:

def __post_init__(self):
    # Extract api_key and base_url from config dict first
    if hasattr(self, "config") and self.config:
        if "api_key" in self.config:
            self.api_key = self.config["api_key"]
        if "base_url" in self.config:
            self.base_url = self.config["base_url"]

    # Set provider-specific defaults
    self.api_key = self.api_key or os.getenv("PROVIDER_API_KEY")
    # ...
    
    super().__post_init__()

Test plan

  • All existing tests pass (390 LLM provider tests)
  • Added tests for config dict initialization:
    • test_initialization_with_api_key_in_config
    • test_initialization_with_base_url_in_config
    • test_initialization_with_api_key_and_base_url_in_config

@claude
Copy link

claude bot commented Jan 24, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 8 files

…roviders

Fixes #68

Providers that inherit from OpenAI-compatible parent classes (OpenRouter,
DeepSeek, XAI, and STT Groq) were ignoring `api_key` passed via the config
dict. This happened because they checked for `api_key` before the config
dict was unpacked by the base class's `__post_init__`.

The fix manually extracts `api_key` and `base_url` from the config dict
before setting provider-specific defaults, ensuring config values take
precedence.

Fixed providers:
- LLM: openrouter, deepseek, xai
- STT: groq

Added regression tests for config dict initialization.
@lfnovo lfnovo force-pushed the fix/config-dict-api-key-issue-68 branch from 633260a to 9bb2bd1 Compare January 24, 2026 12:09
@lfnovo lfnovo merged commit 0d27e21 into main Jan 24, 2026
4 checks passed
@lfnovo lfnovo deleted the fix/config-dict-api-key-issue-68 branch January 24, 2026 12:18
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.

Bug: OpenRouter provider ignores api_key from config dict

1 participant