{"record":{"id":"565fec25d60aa55a","repo":"BerriAI/litellm","slug":"xai-oauth-token-response-was-not-an-object","errorCode":null,"errorMessage":"xAI OAuth token response was not an object","messagePattern":"xAI OAuth token response was not an object","errorType":"exception","errorClass":"XAIOAuthError","httpStatus":null,"severity":"error","filePath":"litellm/llms/xai/oauth.py","lineNumber":327,"sourceCode":"            response: Final = self._client().post(\n                token_endpoint,\n                headers={\n                    \"Accept\": \"application/json\",\n                    \"Content-Type\": \"application/x-www-form-urlencoded\",\n                },\n                data=data,\n            )\n            response.raise_for_status()\n        except httpx.HTTPStatusError as exc:\n            raise XAIOAuthError(\n                f\"xAI OAuth token request failed: {exc.response.status_code} {exc.response.text}\"\n            ) 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):","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/xai/oauth.py#L309-L345","documentation":"Raised in _exchange_token after the token endpoint returned 2xx and the body parsed as JSON, but the parsed value is not a JSON object (e.g. a bare string, number, or list). A compliant OAuth token endpoint must return an object with access_token and friends, so this guards against misconfigured proxies or gateways returning malformed token payloads.","triggerScenarios":"Thrown at litellm/llms/xai/oauth.py:327 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the OAuth flow; the token endpoint returned a JSON value that was not an object, indicating an upstream anomaly.","Check the raw token response with verbose logging to diagnose the endpoint behavior."],"exampleFix":null,"handlingStrategy":"type-guard","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"}