litellm/tests/unit/llms/sap
Tuan Pham 1fdee58d56
fix(sap): token cache (#49260)
* fix(sap): reuse the AI Core OAuth token across requests

* test(sap): add mock AI Core fixture

* test(sap): check chat and embeddings reuse the OAuth token

* test(sap): check the token refreshes inside the expiry buffer

* test(sap): check a reused token refreshes once time enters the buffer

* fix(sap): drop a cached token SAP rejects and refresh short tokens halfway

A 401 from the deployment lookup or the chat or embedding request now
clears the shared OAuth token, so the next call fetches a new one instead
of reusing the rejected token until it nears expiry. Tokens that live two
hours or less refresh halfway through their lifetime instead of on every
call.

* fix(sap): retry a rejected token once and share failed token fetches

The deployment lookup that starts every SAP chat and embedding call now
retries once with a new token after a 401, and the request sends the token
that lookup ended with, so a token SAP rejects no longer fails the call. A
late 401 only drops the token that request sent, never a newer one.
Requests waiting on a failing token fetch get its error instead of each
fetching again behind the lock

* fix(sap): reuse a still-valid token when a refresh fails and drop rejected tokens without the lock

* fix(sap): back off a failed token refresh and never reuse a token that stopped working during it

* fix(sap): never let a failed refresh undo a 401 that drops the cached token

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-23 06:03:52 +00:00
..
chat fix(sap): token cache (#49260) 2026-11-23 06:03:52 +00:00
embed fix(sap): token cache (#49260) 2026-11-23 06:03:52 +00:00
__init__.py
conftest.py fix(sap): token cache (#49260) 2026-11-23 06:03:52 +00:00
test_sap_fetch_creds.py fix(sap): token cache (#49260) 2026-11-23 06:03:52 +00:00