litellm/tests/test_litellm/proxy
Ishaan Jaff b7b20664c1
Gflags worker parameters (#22931)
* feat: add LITELLM_WORKER_STARTUP_HOOKS for per-worker initialization (gflags support)

Add support for running user-defined startup hooks in each worker process
during proxy_startup_event. This enables re-initialization of in-process
state (like gflags.FLAGS) that doesn't survive uvicorn worker spawning.

Usage:
  export LITELLM_WORKER_STARTUP_HOOKS=mymodule:init_fn,other:setup_fn

Hooks run early in proxy_startup_event (before config/DB loading).
Supports both sync and async callables. Errors propagate to prevent
broken workers from serving traffic. No-op when env var is unset.

Includes 5 tests covering sync/async hooks, multiple hooks, error
propagation, and no-hooks-set scenarios.

Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>

* docs: add Worker Startup Hooks page with gflags usage example

- New docs page: docs/proxy/worker_startup_hooks.md
  - Explains the problem (per-process state lost in multi-worker deployments)
  - Full gflags example with wrapper module and startup script
  - Covers multiple hooks, async hooks, error behavior
  - Architecture diagram showing master→worker flow
- Added LITELLM_WORKER_STARTUP_HOOKS to config_settings.md env var table
- Added to sidebar under Setup & Deployment

Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>

* Update litellm/proxy/proxy_server.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Apply suggestion from @greptile-apps[bot]

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-03-06 18:09:57 -08:00
..
_experimental/mcp_server fix(mcp): resolve $ref params and path-level params in OpenAPI spec parsing (#22952) 2026-03-06 18:02:48 -08:00
agent_endpoints fix(agents): PUT update_agent_in_db clears static_headers and extra_headers when omitted 2026-03-05 16:16:21 +05:30
anthropic_endpoints
auth [Feat[ extends OAuth2 M2M authentication support to info routes (/key/info, /team/info, /user/info, /model/info) (#22713) 2026-03-06 17:29:25 -08:00
client
common_utils fix req change 2026-02-28 16:34:23 +05:30
db [Feat] Add Tool Policies for AI Gateway (#22732) 2026-03-03 20:22:20 -08:00
discovery_endpoints
experimental/mcp_server
google_endpoints fix: Metadata / Trace ID Missing in S3 Streaming Callbacks 2026-02-25 14:16:42 +05:30
guardrails azure content enhancement... (#22581) 2026-03-04 10:22:30 -08:00
health_endpoints Prisma DB Failure Detection and Self-Healing (#21059) 2026-03-05 13:44:49 -08:00
hooks Litellm stability fix v2 (#22452) 2026-02-28 15:29:45 -08:00
image_endpoints
management_endpoints Merge pull request #22939 from BerriAI/litellm_hashicorp_vault_backend 2026-03-06 17:59:46 -08:00
management_helpers
middleware feat: add in_flight_requests metric to /health/backlog + prometheus (#22319) 2026-02-27 18:00:50 -08:00
openai_files_endpoint fix(proxy): improve team expiry enforcement validation 2026-03-03 17:29:39 -08:00
pass_through_endpoints Managed batches fixes for Gemini/Vertex 2026-02-28 20:45:16 -05:00
policy_engine
prompts
public_endpoints [Feature] Add /public/endpoints endpoint for provider endpoint support 2026-02-26 18:17:37 -08:00
rag_endpoints
response_api_endpoints
spend_tracking feat(spend-logs): add truncation note when error logs are truncated for DB storage (#22936) 2026-03-05 16:58:46 -08:00
test_configs
ui_crud_endpoints [Fix] PATCH /update/ui_settings now merges with existing record instead of overwriting 2026-03-05 15:49:40 -08:00
vector_store_endpoints
__init__.py
conftest.py
test_aiohttp_cleanup_closed.py
test_api_key_masking_in_errors.py
test_audio_speech_prometheus_hooks.py fix req changes 2026-02-28 21:32:57 +05:30
test_batch_expiry.py fix(proxy): improve team expiry enforcement validation 2026-03-03 17:29:39 -08:00
test_batch_metadata_none_fix.py
test_caching_routes.py
test_chat_completion_metadata.py
test_common_request_processing.py feat(proxy): add key_alias, key_hash, requested_model DD APM span tags (#22710) 2026-03-03 20:22:59 -08:00
test_custom_proxy.py
test_empty_model_list.py [Release Fix] (#22411) 2026-02-28 09:46:35 -08:00
test_enforce_user_param.py
test_fallback_management_endpoints.py
test_fastapi_offline_routes.py
test_health_check_functions.py Fix_mapped tests part 2 2026-02-26 12:43:39 +05:30
test_health_check_max_tokens.py add docs and formatting 2026-02-28 14:08:09 +05:30
test_litellm_pre_call_utils.py Agent Tracing - support context_id based trace id propogation + nested llm calls (#22626) 2026-03-03 18:19:12 -08:00
test_model_dump_with_preserved_fields.py Fix_mapped tests part 2 2026-02-26 12:43:39 +05:30
test_model_id_header_propagation.py
test_prometheus_cleanup.py Add Prometheus child_exit cleanup for gunicorn workers 2026-02-27 16:11:15 -08:00
test_proxy_cli.py Gflags worker parameters (#22931) 2026-03-06 18:09:57 -08:00
test_proxy_server.py Fix inflight mypy 2026-03-02 19:41:32 +05:30
test_proxy_types.py fix: Add PROXY_ADMIN role to system user for key rotation (#21896) 2026-02-27 19:11:29 -08:00
test_proxy_utils.py [Feat[ extends OAuth2 M2M authentication support to info routes (/key/info, /team/info, /user/info, /model/info) (#22713) 2026-03-06 17:29:25 -08:00
test_pyroscope.py
test_response_model_sanitization.py
test_route_a2a_models.py
test_route_llm_request.py
test_shared_health_check.py Fix_mapped tests part 2 2026-02-26 12:43:39 +05:30
test_spend_log_cleanup.py Fix spend log cleanup: lock tracking, integer retention, skip log level 2026-03-03 10:12:08 -08:00
test_swagger_chat_completions.py [Release Fix] (#22411) 2026-02-28 09:46:35 -08:00
test_team_member_update.py
test_tools_allowlist_enforcement.py [Feat] Add Tool Policies for AI Gateway (#22732) 2026-03-03 20:22:20 -08:00
test_update_llm_router_resilience.py fix(proxy): isolate get_config failures from model loading in sync loop 2026-02-26 17:49:44 -03:00