BerriAI/litellm · error · RuntimeError
Token request failed: {msg}
Error message
Token request failed: {msg} What it means
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.
Source
Thrown at litellm/llms/sap/credentials.py:375
resp: httpx.Response | None = None
try:
if cert_pair:
with httpx.Client(cert=cert_pair) as raw_client:
handler = HTTPHandler(client=raw_client)
resp = handler.post(auth_url, data=data, timeout=timeout)
payload = resp.json()
else:
handler = _get_httpx_client()
resp = handler.post(auth_url, data=data, timeout=timeout)
payload = resp.json()
access_token: Final = payload["access_token"]
expires_in: Final = int(payload.get("expires_in", 3600))
expiry_date: Final = datetime.now(timezone.utc) + timedelta(seconds=expires_in)
return f"Bearer {access_token}", expiry_date
except Exception as e:
msg: Final = resp.text if resp is not None else getattr(e, "text", str(e))
raise RuntimeError(f"Token request failed: {msg}") from e
def get_token_creator(
service_key: str | dict | None = None,
profile: str | None = None,
*,
timeout: float = 30.0,
expiry_buffer_minutes: int = 60,
**overrides,
) -> tuple[Callable[[], str], str, str]:
"""
Creates a callable that fetches and caches an OAuth2 bearer token
using credentials from `fetch_credentials()`.
The callable:
- Automatically loads credentials via fetch_credentials(profile, **overrides)
- Fetches a new token only if expired or near expiry
- Caches token thread-safely with a configurable refresh bufferView on GitHub (pinned to 77b7c6c40c)
Solutions
- Inspect msg for the token endpoint's error (invalid client, wrong auth URL, etc.).
- Verify AICORE_AUTH_URL and client credentials.
Example fix
# curl the auth URL with the client id/secret to reproduce the failure.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Triggered when the SAP AI Core token request fails.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/19a8bd63b076fc71.
Report an issue: GitHub.