Repository navigation
Conversation
Merging this PR will not alter performance1 warning
Comparing |
Greptile SummaryThis PR adds per-deployment xAI OAuth credential files, named-account CLI login, and retryable handling for SuperGrok spending limits
Confidence Score: 3/5This PR is not safe to merge until request-level OAuth file overrides are blocked and the explicit repository-rule violations are resolved Normal proxy requests can replace an OAuth-enabled deployment’s credential path and cause upstream calls to execute under another readable local account Files Needing Attention: litellm/llms/xai/oauth.py, litellm/litellm_core_utils/exception_mapping_utils.py, litellm/proxy/proxy_cli.py, tests/test_litellm/llms/xai/test_xai_oauth_multi_account.py
|
| Filename | Overview |
|---|---|
| litellm/llms/xai/oauth.py | Adds explicit credential-file selection but does not constrain request-selected paths to the configured token directory |
| litellm/litellm_core_utils/exception_mapping_utils.py | Adds xAI spending-limit handling to a shared mapper used by many providers |
| litellm/llms/xai/chat/transformation.py | Consistently uses the selected OAuth file for chat authorization and API-base resolution |
| litellm/llms/xai/responses/transformation.py | Propagates the selected OAuth file through Responses authorization and URL resolution |
| litellm/proxy/proxy_cli.py | Adds named-account login but accepts unvalidated account strings when constructing credential paths |
| tests/test_litellm/llms/xai/test_xai_oauth_multi_account.py | Covers multi-account behavior but replaces the production authenticator class rather than injecting a dependency |
Reviews (1): Last reviewed commit: "feat(xai): support multi-account SuperGr..." | Re-trigger Greptile
| if auth_file: | ||
| self.auth_file = auth_file if os.path.isabs(auth_file) else os.path.join(self.token_dir, auth_file) |
There was a problem hiding this comment.
Proxy fields override deployment credentials, and arbitrary readable paths are opened for authorization. How this was verified: Request fields win before file access.
Rule Used: What: Fail any PR which may contains a security in... (source)
Knowledge Base Used: Provider adapters and capabilities
| elif original_exception.status_code == 403 and "spending-limit" in error_str: | ||
| raise RateLimitError( | ||
| message=f"RateLimitError: {exception_provider} - {message}", | ||
| model=model, | ||
| llm_provider=custom_llm_provider, | ||
| response=getattr(original_exception, "response", None), | ||
| litellm_debug_info=extra_information, | ||
| ) |
There was a problem hiding this comment.
Provider Logic Outside Adapter
This adds xAI-specific classification to shared exception mapping, violating the requirement that provider behavior stay under llms/. Fix this before merging.
Rule Used: What: Avoid writing provider-specific code outside... (source)
Knowledge Base Used: Fallbacks, retries, and failure handling
| account: Final = cli_args[2] if len(cli_args) >= 3 else None | ||
| token_dir: Final = get_secret_str("XAI_OAUTH_TOKEN_DIR") or os.path.expanduser( | ||
| "~/.config/litellm/xai_oauth" | ||
| ) | ||
| authenticator: Final = ( | ||
| XAIOAuthAuthenticator(auth_file=os.path.join(token_dir, f"auth-{account}.json")) |
There was a problem hiding this comment.
Account names enter credential paths without validation. Names containing separators can make login fail after the OAuth callback completes.
Knowledge Base Used: Proxy configuration and deployment
| def login(self): | ||
| return {"expires_at": 1234567890} | ||
|
|
||
| monkeypatch.setattr("litellm.llms.xai.oauth.XAIOAuthAuthenticator", FakeAuthenticator) |
There was a problem hiding this comment.
Authenticator Class Monkeypatch
This test replaces the authenticator class, violating the requirement to inject mocked dependencies. Fix this before merging.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
7780025 to
53b1255
Compare
5cfaedb to
712cf29
Compare
7c6fff7 to
623f740
Compare
497ecff to
9d9b6a7
Compare
|
@greptileai review |
|
Automatic reviews are disabled for this repository. |
9d9b6a7 to
15cb9d4
Compare
15cb9d4 to
529b006
Compare
Add per-deployment xai_oauth_token_file so multiple SuperGrok accounts can share one proxy. Map xAI 403 spending-limit to RateLimitError so the router can fail over to another deployment Co-authored-by: HX <HXhlx@users.noreply.github.com>
… client-side opt-ins The token file picks which OAuth account stored on the proxy host signs the request, so allow_client_side_credentials and configurable_clientside_auth_params must not hand it to callers. Only deployment config may set it
…n file handling Move the spending-limit to rate-limit mapping out of the shared exception mapper into XAIChatConfig and XAIResponsesAPIConfig get_error_class. Keep the operator's XAI_OAUTH_AUTH_FILE behaviour, reject symlinks that escape the token dir, report a usage error for unsafe CLI account names, and cover per-account router failover
Adding xai_oauth_token_file to GenericLiteLLMParams adds one unknown argument at every GenericLiteLLMParams(**kwargs) call site. Building the params in responses() with model_validate, which behaves the same for a model without a custom __init__, keeps the basedpyright total below base.
…ith enterprise routes
Route the token file through the shared server-owned gate so it is refused in body litellm_params, stored key/team fallback targets and health check params, and so only proxy admins can set it on a deployment. Drops the parallel operator-only check this replaces
529b006 to
e4942c2
Compare
|
@ryan-crabbe-berri @mateo-berri @joshua-berri @kerry-berri @klu-berri rebased onto main today, CI green, would appreciate a review when you get a chance |
|
@ryan-crabbe-berri @mateo-berri @joshua-berri @kerry-berri @klu-berri all five PRs are rebased onto main and merge clean, CI awaits a workflow approval, reviews welcome when you get a chance |
TLDR
Problem this solves:
How it solves it:
xai_oauth_token_filedeployment param picks that deployment's OAuth accountlitellm xai-oauth login <account>writes a separateauth-<account>.jsonXAI_OAUTH_TOKEN_DIR, symlinks includedUser Flow
Before: an operator with two SuperGrok accounts can serve only one, and traffic stops when it runs out
litellm xai-oauth login, which always writes the singleauth.jsonuse_xai_oauth: truedeployment forxai/grok-4.7under the model namegrok"model": "grok"until the account hits its spending limitspending-limiterror and no other account is triedAfter: the same operator logs in both accounts, and the proxy moves to the second one when the first runs out
litellm xai-oauth login aliceandlitellm xai-oauth login bob, which writeauth-alice.jsonandauth-bob.jsongrokdeployments, each with its ownxai_oauth_token_fileandorderspending-limitxai_oauth_token_filein the body, itslitellm_params, or a fallback target gets a 401 "Rejected Request", so they can't pick another accountPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Shared setup: a local proxy with no database,
XAI_OAUTH_TOKEN_DIRpointed at an empty directory, and this config.allow_client_side_credentialsis on to show that even the proxy-wide opt-in doesn't unlock the fieldBefore (d553123)
Token file in the request body
curl -s http://localhost:4243/v1/chat/completions -H 'Authorization: Bearer sk-pr40242-local' -H 'Content-Type: application/json' -d '{"model":"grok","messages":[{"role":"user","content":"hi"}],"xai_oauth_token_file":"auth-bob.json"}'HTTP 401"litellm.AuthenticationError: xAI OAuth login required. Run `litellm xai-oauth login`."Token file in body litellm_params
"litellm_params":{"xai_oauth_token_file":"auth-bob.json"}in the bodyHTTP 429all_deployments_in_cooldownfrom the previous failureToken file in a fallback target
"fallbacks":[{"model":"grok","xai_oauth_token_file":"auth-bob.json"}]in the bodyHTTP 429all_deployments_in_cooldownAfter (9d9b6a7d5f)
Token file in the request body
curl -s http://localhost:4242/v1/chat/completions -H 'Authorization: Bearer sk-pr40242-local' -H 'Content-Type: application/json' -d '{"model":"grok","messages":[{"role":"user","content":"hi"}],"xai_oauth_token_file":"auth-bob.json"}'HTTP 401"Rejected Request: xai_oauth_token_file is a server-owned workload identity federation or OAuth token exchange parameter and cannot be set in a request body. A proxy admin configures it on the deployment or on a stored credential."Token file in body litellm_params
"litellm_params":{"xai_oauth_token_file":"auth-bob.json"}in the bodyHTTP 401with the same "Rejected Request: xai_oauth_token_file is a server-owned ..." messageToken file in a fallback target
"fallbacks":[{"model":"grok","xai_oauth_token_file":"auth-bob.json"}]in the bodyHTTP 401with the same "Rejected Request: xai_oauth_token_file is a server-owned ..." messageA plain request with no override goes to the deployment's own
auth-alice.json, which isn't in the empty token directory, so it returnsHTTP 401"xAI OAuth login required"Type
🆕 New Feature
Caveats (if any)
Medium
Low