litellm/ui/litellm-dashboard/src/utils
Mateo Wang 68a8b12ab3
fix(proxy)!: end a chat completions stream with an error event when a guardrail blocks mid-stream (#46953)
* fix(proxy): end a chat completions stream with an error event when a guardrail blocks mid-stream

A streaming guardrail that raised an HTTPException after the first chunk re-raised it inside the SSE generator, so the 200 body was cut off with no finish_reason, no error event and no [DONE]. Build the error frame through sse_error_payload instead, keeping the status, message and structured detail, and encode values JSON cannot represent as strings so the frame always goes out.

* fix(proxy): keep early guardrail blocks on their HTTP status and end mid-stream errors with [DONE]

A guardrail block before the first chunk is raised again, so its response stays the
400 event-stream body it is on main. A mid-stream error event now carries the failure
hook's replacement error when one is returned, is followed by data: [DONE] on
OpenAI-format streams, and leaves the Gemini route's raise unchanged. Error details
JSON cannot encode are written as strings instead of breaking the event.

* fix(proxy): keep a per-chunk guardrail block on the first chunk on its event-stream 400

* fix(proxy): treat a keepalive ping as a started stream so a later guardrail block ends in-band

* fix(proxy): encode non-JSON guardrail details in early stream error frames

An early guardrail block whose detail holds a value JSON cannot encode sent
400 headers and then cut the body. The error frame now writes such a value as
its string form, the same as the mid-stream event. The keepalive test now runs
on a virtual clock instead of real sleeps.

* fix(proxy): show an in-band stream error event as an error in the CLI, Python client, and dashboard playgrounds

ChatClient.completions_stream raises StreamError on a data frame carrying an error, so litellm-proxy chat prints the block reason and keeps the partial reply out of history. The prompt playground and the Interactions playground read the same frame through a shared streamErrorMessage helper. Adds the audit's integration cells for chat stream error events, and makes the endpoint tests' failure-hook mocks return None so they check the real error payload.

* fix(proxy): print stream error text verbatim in the CLI and read split error events in the prompt playground

The CLI printed the server's error message as Rich markup, so a closing tag like [/pii] in a guardrail message crashed lite chat. The prompt playground now buffers partial lines across reads, ChatClient raises only on a non-empty error, StreamError redacts keys like the other client exceptions, and StreamError is exported from litellm.proxy.client

* fix(proxy): print CLI stream errors without Rich highlighting or emoji codes

* test(proxy): cover the CLI's plain-text 400 error print

* test(proxy): annotate the new client stream test locals as Final

* fix(proxy): send the failure hook replacement on Responses streams and before the first chunk

* fix(proxy): end a Responses stream with response.failed when it fails on a built-in exception

* fix(proxy): keep a failure hook replacement before the first chunk in-band so bare stream routes still answer it

A non-HTTP failure whose hook returns an HTTP error was raised before the first
chunk, which create_response turned into the hook's status but which a bare
StreamingResponse route such as /queue/chat/completions answered as a 200 with
zero bytes. Only the original HTTP errors raise now. The replacement goes out as
the stream's error event, which create_response still answers with the hook's
status as a JSON error.

Adds audit round 2's integration cells for failure hook replacements on chat and
Responses streams, built-in exceptions on Responses streams, and the Python client.

* test(proxy): cover a queue stream whose failure hook replaces a failure before the first chunk

The audit cell posts to /queue/chat/completions with a callback that raises before the first chunk and a failure hook that answers 403. It checks for a 200 event stream whose only event is the replacement, then one [DONE], with the callback's own message absent
2026-10-17 18:00:12 -07:00
..
activityTimestamp.test.ts feat: improve Lens dev seeding and live UI (#44468) 2026-10-04 01:03:11 +00:00
activityTimestamp.ts feat: improve Lens dev seeding and live UI (#44468) 2026-10-04 01:03:11 +00:00
budgetUtils.ts Show absolute date in Budget Reset column 2026-04-23 15:57:22 -07:00
capabilities.test.ts fix(proxy): let org admins view their organization's usage (#37235) 2026-08-18 14:44:36 -07:00
capabilities.ts fix(proxy): let org admins view their organization's usage (#37235) 2026-08-18 14:44:36 -07:00
cookieUtils.test.ts fix(ui): store SSO exchange token via storeLoginToken to keep Secure flag (#45840) 2026-10-10 13:33:03 -07:00
cookieUtils.ts fix(ui): break logout redirect loop across origins (#29360) 2026-05-30 19:02:29 -07:00
dataUtils.test.ts refactor(ui): move per-second cost formatter to dataUtils and type transformModelData input 2026-09-18 15:48:56 +00:00
dataUtils.ts feat(ui): show invitation and reset password links in a copyable field (#44454) 2026-10-03 16:23:13 -07:00
debounceConstants.ts refactor(ui): standardize debounce waits behind shared DEBOUNCE_WAIT_MS constant (#33040) 2026-07-13 12:19:57 -07:00
entityLinks.test.ts fix(ui): link model access group chips to the access group filter (#45402) 2026-10-08 15:32:33 -07:00
entityLinks.ts fix(ui): link model access group chips to the access group filter (#45402) 2026-10-08 15:32:33 -07:00
errorPatterns.ts added and ran prettier autoformatter 2025-10-04 18:19:48 -07:00
errorUtils.test.ts Add unit tests for 5 previously untested UI dashboard files 2026-03-16 12:53:20 -07:00
errorUtils.ts style(ui): run prettier --write across the dashboard (#29622) 2026-06-04 11:37:54 -07:00
jwtUtils.test.ts useAuthorized refactor 2026-02-04 16:37:45 -08:00
jwtUtils.ts useAuthorized refactor 2026-02-04 16:37:45 -08:00
keyExpiryUtils.test.ts fix(ui): require new expiration when regenerating an expired key (#29838) 2026-06-06 09:18:19 -07:00
keyExpiryUtils.ts fix(ui): require new expiration when regenerating an expired key (#29838) 2026-06-06 09:18:19 -07:00
keyUpdateUtils.test.ts Key Max Budget Removal Error Fix 2025-10-17 12:04:58 -07:00
keyUpdateUtils.ts Key Max Budget Removal Error Fix 2025-10-17 12:04:58 -07:00
licenseUtils.test.ts feat(ui): replace deployment warning banners with a health icon, alert banner and panel (#46498) 2026-10-14 18:32:40 -07:00
licenseUtils.ts feat(ui): replace deployment warning banners with a health icon, alert banner and panel (#46498) 2026-10-14 18:32:40 -07:00
localStorageUtils.test.ts test(ui): split the vitest suite into unit, component, integration and type projects (#37488) 2026-08-19 20:40:14 +00:00
localStorageUtils.ts feat: hide new badges 2025-12-31 10:42:34 -08:00
maskedSecretUtils.ts fix(ui): stop credential edit from persisting the masked api key (#33797) 2026-07-17 18:25:24 -07:00
mcpHeaderUtils.test.ts feat(mcp): Add tool call and tool list support via UI for Oauth mcps (#28454) 2026-05-22 09:04:04 -07:00
mcpHeaderUtils.ts fix(mcp): load MCP tool configuration tools via the OBO/passthrough-aware GET path (#29960) 2026-06-08 19:58:51 -07:00
mcpTokenStore.test.ts test(ui): split the vitest suite into unit, component, integration and type projects (#37488) 2026-08-19 20:40:14 +00:00
mcpTokenStore.ts refactor(ui): route MCP session tokens through the shared storage helper 2026-08-04 14:15:29 -07:00
mcpToolCrudClassification.test.ts Add unit tests for 5 previously untested UI dashboard files 2026-03-16 12:53:20 -07:00
mcpToolCrudClassification.ts feat(ui): group MCP tools by CRUD risk category in allowlist panels (#23403) 2026-03-11 21:15:25 -07:00
modelPermissions.test.ts fix(proxy): enforce internal-user model creation prohibition (#44438) 2026-10-05 11:32:05 -07:00
modelPermissions.ts fix(proxy): enforce internal-user model creation prohibition (#44438) 2026-10-05 11:32:05 -07:00
pkce.ts Extract shared PKCE helpers into src/utils/pkce.ts 2026-04-16 10:35:52 -07:00
promptCacheUsage.test.ts feat(ui): show provider prompt cache tokens in chat response metrics (#36827) 2026-08-13 16:58:14 -07:00
promptCacheUsage.ts feat(ui): show provider prompt cache tokens in chat response metrics (#36827) 2026-08-13 16:58:14 -07:00
proxyUtils.test.ts style(ui): run prettier --write across the dashboard (#29622) 2026-06-04 11:37:54 -07:00
proxyUtils.ts added and ran prettier autoformatter 2025-10-04 18:19:48 -07:00
ptuDatetime.test.ts feat(ptu): PTU inputs on the model form and flat cost on the Usage page (#35393) 2026-08-10 11:05:06 -07:00
ptuDatetime.ts feat(ptu): PTU inputs on the model form and flat cost on the Usage page (#35393) 2026-08-10 11:05:06 -07:00
ptuModelInfo.test.ts feat(ptu): gate PTU flat-cost attribution behind an opt-in env var (#36138) 2026-08-10 12:23:20 -07:00
ptuModelInfo.ts feat(ptu): gate PTU flat-cost attribution behind an opt-in env var (#36138) 2026-08-10 12:23:20 -07:00
ptuValidation.test.ts fix(ptu): stop per-token billing on a PTU-configured deployment (#36829) 2026-08-13 20:16:12 -07:00
ptuValidation.ts refactor(ui): move the model info edit form off antd Form (#37392) 2026-08-18 17:40:49 -07:00
returnUrlUtils.test.ts feat(helm): support a separate hostname per component in the componentized deploy (#46360) 2026-10-14 14:56:36 -07:00
returnUrlUtils.ts feat(helm): support a separate hostname per component in the componentized deploy (#46360) 2026-10-14 14:56:36 -07:00
roles.test.ts fix(ui): gate MCP live connections tab to proxy admin tier roles 2026-09-17 22:36:00 +00:00
roles.ts Merge pull request #40737 from BerriAI/litellm_logs_user_email_display 2026-09-18 14:20:16 -07:00
searchUtils.test.ts feat(ui): add search to Agent Hub tab and admin agents table 2026-09-01 11:46:58 -07:00
searchUtils.ts feat(ui): add search to Agent Hub tab and admin agents table 2026-09-01 11:46:58 -07:00
secureStorage.ts style(ui): run prettier --write across the dashboard (#29622) 2026-06-04 11:37:54 -07:00
sentinels.ts feat(ui): link the User, Team and Created By cells on the Virtual Keys page 2026-09-10 15:55:03 -07:00
streamErrorMessage.test.ts fix(proxy)!: end a chat completions stream with an error event when a guardrail blocks mid-stream (#46953) 2026-10-17 18:00:12 -07:00
streamErrorMessage.ts fix(proxy)!: end a chat completions stream with an error event when a guardrail blocks mid-stream (#46953) 2026-10-17 18:00:12 -07:00
teamUtils.test.ts Deprecate useTeam in favor of react query 2025-12-23 20:15:42 -08:00
teamUtils.ts Deprecate useTeam in favor of react query 2025-12-23 20:15:42 -08:00
textUtils.test.ts Adding unit testing coverage 2026-01-03 17:25:46 -08:00
textUtils.ts [Feature] UI - Add LiteLLM Params to Edit Model (#16496) 2025-11-11 18:52:11 -08:00
uiHref.test.ts refactor(ui): route the sidebar by pathname and shrink the ?page= shim to a redirect table 2026-09-05 16:44:11 -07:00
uiHref.ts refactor(ui): route the sidebar by pathname and shrink the ?page= shim to a redirect table 2026-09-05 16:44:11 -07:00
versionUtils.test.ts feat(ui): add upgrade banner with latest release changelog stats 2026-09-09 10:38:45 -07:00
versionUtils.ts feat(ui): add upgrade banner with latest release changelog stats 2026-09-09 10:38:45 -07:00