litellm/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
..
html_forms feat(sso): show full IdP claims in /sso/debug/callback (#27498) 2026-05-08 17:39:39 -07:00
admin_ui_utils.py [UI Polish] - Polish login screen (#9778) 2025-04-05 14:56:03 -07:00
banner.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
cache_coordinator.py refactor: remove AuthMetrics and related combined_view query metrics 2026-04-30 22:13:11 +00:00
cache_pydantic_utils.py Enhance caching mechanism by integrating CacheCodec for serialization across various components. Introduce the enable_redis_auth_cache flag to control Redis integration for user_api_key_cache, improving performance in multi-worker deployments. Update documentation and tests to reflect these changes. 2026-04-24 01:30:01 +00:00
callback_utils.py fix(proxy): strip LiteLLM policy tracking from OpenAI batch metadata (#28425) 2026-05-26 11:35:42 -07:00
custom_openapi_spec.py build(deps-dev): bump black to 26.3.1 and apply formatting (#28525) 2026-05-21 17:24:18 -07:00
debug_utils.py chore(proxy): guard sensitive public endpoints 2026-04-30 11:52:47 -07:00
encrypt_decrypt_utils.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
expired_ui_session_key_cleanup_manager.py refactor: replace DualCache with UserApiKeyCache in multiple modules 2026-04-30 22:40:52 +00:00
get_routes.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
http_parsing_utils.py chore(ci): merge dev branch (#28801) 2026-05-25 13:44:49 -07:00
key_rotation_manager.py Litellm ishaan april4 2 (#25150) 2026-04-04 23:09:42 +00:00
load_config_utils.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
openai_endpoint_utils.py build(deps-dev): bump black to 26.3.1 and apply formatting (#28525) 2026-05-21 17:24:18 -07:00
openapi_schema_compat.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
path_utils.py fix(ci): resolve mypy and ruff lint failures 2026-04-15 21:12:51 -07:00
performance_utils.md build: migrate packaging, CI, and Docker from Poetry to uv (#25007) 2026-04-09 11:46:23 -07:00
performance_utils.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
proxy_state.py (feat) UI - Disable Usage Tab once SpendLogs is 1M+ Rows (#7208) 2024-12-12 18:43:17 -08:00
rbac_utils.py refactor(rbac): narrow org-admin restriction to key generation only 2026-04-24 19:36:31 -07:00
realtime_utils.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
reset_budget_job.py feat: litellm shin agent oss staging 05 10 2026 (#27631) 2026-05-11 20:31:43 -07:00
resource_ownership.py fix(ownership): reject identity-less callers instead of sharing a sentinel scope 2026-05-04 23:40:22 +00:00
static_asset_utils.py fix(static-assets): browser-load remote branding assets 2026-04-30 11:30:57 -07:00
swagger_utils.py show all error types on swagger 2024-08-29 18:50:41 -07:00
timezone_utils.py fix(budget): fix timezone config lookup and replace hardcoded timezone map with ZoneInfo (#21754) 2026-02-21 19:35:06 -08:00
user_api_key_cache.py refactor: replace DualCache with UserApiKeyCache in multiple modules 2026-04-30 22:40:52 +00:00