{"record":{"id":"19a8bd63b076fc71","repo":"BerriAI/litellm","slug":"token-request-failed-msg","errorCode":null,"errorMessage":"Token request failed: {msg}","messagePattern":"Token request failed: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"litellm/llms/sap/credentials.py","lineNumber":375,"sourceCode":"\n    resp: httpx.Response | None = None\n    try:\n        if cert_pair:\n            with httpx.Client(cert=cert_pair) as raw_client:\n                handler = HTTPHandler(client=raw_client)\n                resp = handler.post(auth_url, data=data, timeout=timeout)\n                payload = resp.json()\n        else:\n            handler = _get_httpx_client()\n            resp = handler.post(auth_url, data=data, timeout=timeout)\n            payload = resp.json()\n        access_token: Final = payload[\"access_token\"]\n        expires_in: Final = int(payload.get(\"expires_in\", 3600))\n        expiry_date: Final = datetime.now(timezone.utc) + timedelta(seconds=expires_in)\n        return f\"Bearer {access_token}\", expiry_date\n    except Exception as e:\n        msg: Final = resp.text if resp is not None else getattr(e, \"text\", str(e))\n        raise RuntimeError(f\"Token request failed: {msg}\") from e\n\n\ndef get_token_creator(\n    service_key: str | dict | None = None,\n    profile: str | None = None,\n    *,\n    timeout: float = 30.0,\n    expiry_buffer_minutes: int = 60,\n    **overrides,\n) -> tuple[Callable[[], str], str, str]:\n    \"\"\"\n    Creates a callable that fetches and caches an OAuth2 bearer token\n    using credentials from `fetch_credentials()`.\n\n    The callable:\n      - Automatically loads credentials via fetch_credentials(profile, **overrides)\n      - Fetches a new token only if expired or near expiry\n      - Caches token thread-safely with a configurable refresh buffer","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/sap/credentials.py#L357-L393","documentation":"The OAuth2 token request to the SAP AI Core auth_url failed (non-success response or error payload); the raised error embeds the provider's msg so the caller can see why the access token could not be obtained.","triggerScenarios":"Triggered when the SAP AI Core token request fails.","commonSituations":"See trigger scenarios.","solutions":["Inspect msg for the token endpoint's error (invalid client, wrong auth URL, etc.).","Verify AICORE_AUTH_URL and client credentials."],"exampleFix":"# curl the auth URL with the client id/secret to reproduce the failure.","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"}