{"record":{"id":"a11bcaebc98c63a8","repo":"BerriAI/litellm","slug":"xai-oauth-token-response-missing-access-token","errorCode":null,"errorMessage":"xAI OAuth token response missing access_token","messagePattern":"xAI OAuth token response missing access_token","errorType":"exception","errorClass":"XAIOAuthError","httpStatus":null,"severity":"error","filePath":"litellm/llms/xai/oauth.py","lineNumber":339,"sourceCode":"            ) from exc\n        try:\n            body: Final = response.json()\n        except ValueError as exc:\n            raise XAIOAuthError(\"xAI OAuth token response was not valid JSON\") from exc\n        if not isinstance(body, dict):\n            raise XAIOAuthError(\"xAI OAuth token response was not an object\")\n        return body\n\n    def _build_auth_record(\n        self,\n        token_payload: dict[str, Any],\n        token_endpoint: str,\n        fallback_refresh_token: str | None = None,\n    ) -> dict[str, Any]:\n        access_token: Final = token_payload.get(\"access_token\")\n        refresh_token: Final = token_payload.get(\"refresh_token\") or fallback_refresh_token\n        if not access_token:\n            raise XAIOAuthError(\"xAI OAuth token response missing access_token\")\n        if not refresh_token:\n            raise XAIOAuthError(\"xAI OAuth token response missing refresh_token\")\n        expires_in: Final = token_payload.get(\"expires_in\") or 3600\n        try:\n            expires_at = int(time.time() + int(expires_in))\n        except (TypeError, ValueError):\n            expires_at = int(time.time() + 3600)\n        return {\n            \"access_token\": access_token,\n            \"refresh_token\": refresh_token,\n            \"id_token\": token_payload.get(\"id_token\"),\n            \"token_type\": token_payload.get(\"token_type\") or \"Bearer\",\n            \"token_endpoint\": token_endpoint,\n            \"expires_at\": expires_at,\n        }\n\n    def _refresh_tokens(self, auth_data: dict[str, Any]) -> dict[str, Any]:\n        token_endpoint = auth_data.get(\"token_endpoint\")","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/xai/oauth.py#L321-L357","documentation":"XAIOAuthError raised in _build_auth_record when the token payload contains no access_token: the exchange response parsed fine but is unusable for authenticated API calls, so the auth record is not persisted.","triggerScenarios":"Thrown at litellm/llms/xai/oauth.py:339 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Restart the login flow; the token response lacked access_token, which usually means the grant failed.","Verify the requested scopes and client configuration with xAI."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}