Files
litellm/tests/test_litellm/proxy/spend_tracking
milan-berri efaafbbd02 fix(proxy): strip NUL bytes from spend log payloads to prevent PostgreSQL 22P05 (#29515)
A raw NUL byte (\x00) in request/response content is serialized by json.dumps
into the \u0000 JSON escape. When update_spend_logs writes this to the
LiteLLM_SpendLogs jsonb columns, Postgres rejects the whole batch with
error 22P05 ("unsupported Unicode escape sequence ... cannot be converted to
text"), crashing the periodic update_spend job and dropping the spend-log batch.

Centralize stripping in safe_dumps (covers metadata/response paths and any
future caller) and route the messages, proxy_server_request, request_tags, and
response (string branch) payloads through it instead of json.dumps. Dict keys
are stripped too.

Adds regression tests for safe_dumps and the spend-log message, response, and
request_tags payload builders.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 12:07:11 -07:00
..