fix: auto-set provider API key env var for LiteLLM validation
LiteLLM validates provider-specific API key env vars before making calls. When using custom headers, auto-set ANTHROPIC_API_KEY or OPENAI_API_KEY to pass validation (actual auth still uses extra_headers). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -84,6 +84,13 @@ class LLMService:
|
||||
self._extra_headers[self._api_key_header] = self._api_key
|
||||
logger.info(f"Using custom API key header: {self._api_key_header}")
|
||||
|
||||
# LiteLLM requires provider-specific API key env var to pass validation
|
||||
# Set it to satisfy the check (actual auth uses extra_headers)
|
||||
if self._model.startswith("anthropic/"):
|
||||
os.environ.setdefault("ANTHROPIC_API_KEY", self._api_key)
|
||||
elif self._model.startswith("openai/"):
|
||||
os.environ.setdefault("OPENAI_API_KEY", self._api_key)
|
||||
|
||||
if self._mock_mode:
|
||||
logger.info("LLMService running in MOCK mode (forced by LLM_MOCK_MODE)")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user