litellm/tests/test_litellm/proxy/common_utils
Shivam Rawat fbff60e9d9
fix(proxy): strip LiteLLM policy tracking from OpenAI batch metadata (#28425)
* fix(proxy): strip LiteLLM policy tracking from OpenAI batch metadata

Batch create was failing with `Invalid type for 'metadata.applied_policies':
expected a string, but got an array instead` whenever a policy attachment
matched the request. The policy engine helpers wrote `applied_policies`,
`applied_guardrails`, and `policy_sources` into `data["metadata"]`
unconditionally, and `/v1/batches` forwarded that dict straight to OpenAI,
which only accepts string values.

- Route proxy-internal tracking into `litellm_metadata` for batch/file
  routes via a shared `_get_or_create_proxy_metadata_bucket` helper.
- Sanitize `data["metadata"]` in `create_batch` to drop known internal
  keys and non-string values before building the OpenAI request.
- Cover both behaviors with unit + endpoint tests.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(proxy): merge metadata buckets for batch policy response headers

Ensure get_logging_caching_headers reads both metadata and litellm_metadata so policy/guardrail headers are emitted on batch routes with user metadata, and log dropped non-string OpenAI metadata at debug level.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-26 11:35:42 -07:00
..
test_cache_codec.py
test_callback_utils.py fix(proxy): strip LiteLLM policy tracking from OpenAI batch metadata (#28425) 2026-05-26 11:35:42 -07:00
test_custom_openapi_spec.py
test_expired_ui_session_key_cleanup_manager.py
test_get_routes.py
test_http_parsing_utils.py chore(ci): merge dev branch (#28314) 2026-05-20 17:47:33 -07:00
test_key_rotation_e2e.py Litellm key rotation bug (#27756) 2026-05-12 17:16:37 -07:00
test_key_rotation_integration.py
test_key_rotation_lock.py
test_key_rotation_manager.py
test_load_config_utils.py
test_openai_endpoint_utils.py
test_path_utils.py
test_reset_budget_job.py feat: litellm shin agent oss staging 05 10 2026 (#27631) 2026-05-11 20:31:43 -07:00
test_static_asset_utils.py
test_timezone_utils.py
test_upsert_budget_membership.py
test_user_api_key_cache.py fix import error 2026-05-01 00:29:13 +00:00