Add dedicated xai_key and fallback logic for xAI API key - #28060
Add dedicated xai_key and fallback logic for xAI API key#28060PeterDaveHello wants to merge 6 commits into
Conversation
Squash-merged by litellm-agent from FabrizioCafolla's PR.
…erriAI#27927) Squash-merged by litellm-agent from Cyberfilo's PR.
Squash-merged by litellm-agent from tomdee's PR.
Squash-merged by litellm-agent from escon1004's PR.
dac912f to
7ff036e
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR introduces
Confidence Score: 5/5Safe to merge — the change is purely additive, backward-compatible, and well-covered by tests. All three xAI code paths (chat, responses, realtime) correctly delegate to the centralized resolver, which is additive by design: the new No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/xai/common_utils.py | Adds legacy_generic_before_env flag to get_api_key, centralizing xAI key resolution with two distinct priority chains; error message improved. No logic errors found. |
| litellm/llms/xai/chat/transformation.py | Delegates key resolution to XAIModelInfo.get_api_key; behavior preserved for existing callers, new xai_key fallback added cleanly. |
| litellm/llms/xai/responses/transformation.py | Migrates key resolution to the shared helper with legacy_generic_before_env=True, preserving the historical litellm.api_key → XAI_API_KEY ordering. Updated error message is more descriptive. |
| litellm/realtime_api/main.py | Replaces inline 3-step fallback with XAIModelInfo.get_api_key(..., legacy_generic_before_env=True), keeping the same effective order while gaining xai_key support. |
| tests/test_litellm/llms/xai/test_xai_key_fallback.py | 20 new mock-only tests covering all fallback orderings for the resolver, chat, responses, realtime, and model-listing paths. No real network calls. |
Reviews (2): Last reviewed commit: "Add dedicated xai_key and fallback logic..." | Re-trigger Greptile
|
🤖 litellm-agent: Auto-merge skipped — the staging branch Please rebase your branch onto |
7ff036e to
946ddb4
Compare
|
|
|
Rebased onto shin_agent_oss_staging_05_16_2026 and pushed as requested. |
|
The requested rebase looks ... strange. |
Add a provider-specific litellm.xai_key fallback for xAI chat, responses, and realtime requests. Keep the Responses API and realtime fallback order compatible by preserving litellm.api_key before XAI_API_KEY when no explicit provider-specific key is set.
946ddb4 to
b5542dc
Compare
|
🤖 litellm-agent: Auto-merge skipped — the staging branch Please rebase your branch onto |
|
@Sameerlite, is there anything I can do to make it right? |
|
Extremely sorry about this. the branch was deleted as a part of cleanup process. Can you please create a new one with litellm_internal_staging |
|
@Sameerlite, thanks, I'm willing to, but also a little bit frustrated and afraid of the same thing happening once again. Is there any chance of preventing this situation? |
|
litellm_internal_staging doesn't get deleted. It's the main branch. So it should not happen |
|
Hi @Sameerlite, I opened a fresh replacement PR targeting |
Relevant issues
Replaces #18660 because GitHub would not allow reopening it after the branch
was force-pushed/recreated.
Addresses #18660 (comment).
Linear ticket
N/A
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit.venv/bin/pytest tests/test_litellm/llms/xai/test_xai_key_fallback.py -q.venv/bin/pytest tests/test_litellm/llms/xai/test_xai_chat_transformation.py tests/test_litellm/llms/xai/responses/test_xai_responses_transformation.py -q@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
Type
🐛 Bug Fix
✅ Test
Changes
litellm.xai_keyfallback for xAI API key resolutionlitellm.api_keybeforeXAI_API_KEYbehavior