{"record":{"id":"f05b9dec3d57f214","repo":"BerriAI/litellm","slug":"token-exchange","errorCode":"token_exchange","errorMessage":"Token endpoint returned invalid JSON: {json_err}","messagePattern":"Token endpoint returned invalid JSON: (.+?)","errorType":"exception","errorClass":"ProxyException","httpStatus":401,"severity":"error","filePath":"litellm/proxy/management_endpoints/ui_sso.py","lineNumber":3881,"sourceCode":"        return code_verifier, code_challenge\n\n    @staticmethod\n    def _validate_token_response(response: \"httpx.Response\") -> dict:\n        \"\"\"\n        Parse and validate the token endpoint response.\n\n        Ensures the response is valid JSON, a dict, and contains a non-null\n        access_token string. Raises ProxyException on any validation failure.\n        \"\"\"\n        try:\n            token_response_raw: Final[object] = _as_object(response.json())\n        except Exception as json_err:\n            verbose_proxy_logger.error(\n                \"Failed to parse token response as JSON: %s. Body: %s\",\n                json_err,\n                response.text[:500],\n            )\n            raise ProxyException(\n                message=f\"Token endpoint returned invalid JSON: {json_err}\",\n                type=ProxyErrorTypes.auth_error,\n                param=\"token_exchange\",\n                code=status.HTTP_401_UNAUTHORIZED,\n            )\n\n        if not isinstance(token_response_raw, dict):\n            verbose_proxy_logger.error(\n                \"Token endpoint returned non-dict JSON (type=%s). Body: %s\",\n                type(token_response_raw).__name__,\n                response.text[:500],\n            )\n            raise ProxyException(\n                message=(\n                    f\"Token endpoint returned unexpected response format \"\n                    f\"(expected JSON object, got {type(token_response_raw).__name__})\"\n                ),\n                type=ProxyErrorTypes.auth_error,","sourceCodeStart":3863,"sourceCodeEnd":3899,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/ui_sso.py#L3863-L3899","documentation":"ProxyException raised when the SSO identity provider's token endpoint responds with a body that is not valid JSON (json parse threw); the parse exception text is embedded. Fires when the IdP returns an HTML error page, a non-JSON payload, or truncated body at the /token step of the OAuth code exchange.","triggerScenarios":"Thrown at litellm/proxy/management_endpoints/ui_sso.py:3881 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the GENERIC_TOKEN_ENDPOINT returns valid JSON; check the IdP configuration and proxy logs."],"exampleFix":null,"handlingStrategy":"try-catch","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-14T05:17:10.506Z"}