litellm/litellm
Alexsander Hamir eb5031da1e
[Perf] Fix bottlenecks degrading realtime endpoint performance (#16670)
* Cache realtime websocket request body

Move the realtime request payload builder out of the websocket handler and wrap it with an LRU cache so repeated connections reuse the same bytes object. This keeps the JSON formatting cost down while bounding memory usage.

* Optimize realtime websocket caching

Refactored /v1/realtime to use cached helpers for both the JSON body and query params, introduced a reusable request-scope template, and optimized header handling to avoid redundant work.

* Refine realtime websocket header handling

* Reuse websocket scope headers in auth

* Refactor realtime request body helper

Move the realtime request body formatter into proxy common utils so it can be reused across modules. Reuse it in the websocket auth flow to share LRU caching and avoid ad hoc byte builders.

* fix: revert to old pattern

The old pattern was necessary, we can just return the optimized function instead.

* Reuse SSL context for realtime

Create a shared SSLContext for OpenAI realtime websocket dials and pass it into websockets.connect so we stop re-reading verify paths on every session.

* feat: reuse shared TLS context for realtime websockets

- add `SHARED_REALTIME_SSL_CONTEXT` helper so all realtime websocket clients share the same TLS settings
- wire the shared context into OpenAI, Azure, custom HTTPX handlers, and realtime health checks
- update realtime tests to assert that the expected SSL context is passed to `websockets.connect`

This keeps TLS configuration consistent and avoids recreating SSL contexts per connection.

* Reuse HTTP SSL context for realtime

Remove the standalone realtime SSL helper, expose a shared context directly from the HTTP handler, and point all realtime websocket clients and tests to it. Add the websocket header comparison tool.

* Lazy-load shared realtime SSL context

Fix circular imports introduced by eagerly instantiating the shared TLS context. Make the HTTP handler lazily create the context and have realtime clients/tests fetch it on demand, keeping configuration consistent without breaking startup.

* add: unit test for realtime LRU caches

* fix: merge conflict with imports
2025-11-22 10:01:02 -08:00
..
anthropic_interface [Feat] Allow using litellm.completion with /v1/messages API Spec (use gpt-4, gemini etc with claude code) (#11502) 2025-06-06 20:35:53 -07:00
assistants Contributor PR - Support OPENAI_BASE_URL in addition to OPENAI_API_BASE (#9995) (#10423) 2025-04-29 21:27:37 -07:00
batch_completion (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
batches [Infra] CI/CD Fixes (#16937) 2025-11-21 13:58:19 -08:00
caching fix redis event loop closed at first call (#16913) 2025-11-21 19:15:56 -08:00
completion_extras Litellm sameer nov 3 stable branch (#16963) 2025-11-22 09:35:05 -08:00
containers Add E2E Container API Support (#16136) 2025-11-01 14:03:51 -07:00
endpoints/speech/speech_to_completion_bridge fix: fix import errors 2025-09-14 09:32:21 -07:00
experimental_mcp_client [Feat] mcp resources support (#16800) 2025-11-20 14:53:44 -08:00
files feat(managed_files.py): support /delete for files + feat(managed_batches): support /cancel for batches (#16387) 2025-11-18 17:36:26 -08:00
fine_tuning Litellm managed file updates combined (#11040) 2025-05-22 17:20:41 -07:00
google_genai fix test /generateContent route 2025-10-04 10:49:46 -07:00
images fix: forward OpenAI organization for image generation (#16607) 2025-11-13 21:51:27 -08:00
integrations fix: arize phoenix logging (#16301) 2025-11-21 18:46:18 -08:00
litellm_core_utils Litellm sameer nov 3 stable branch (#16963) 2025-11-22 09:35:05 -08:00
llms [Perf] Fix bottlenecks degrading realtime endpoint performance (#16670) 2025-11-22 10:01:02 -08:00
ocr [Feat] /ocr - Add VertexAI OCR provider support + cost tracking (#16216) 2025-11-03 15:56:49 -08:00
passthrough working - errors from bedrock through pass throughs 2025-10-16 15:40:42 -07:00
proxy [Perf] Fix bottlenecks degrading realtime endpoint performance (#16670) 2025-11-22 10:01:02 -08:00
realtime_api [Perf] Fix bottlenecks degrading realtime endpoint performance (#16670) 2025-11-22 10:01:02 -08:00
rerank_api [Feat] Add Nvidia NIM Rerank Support (#15152) 2025-10-02 18:58:52 -07:00
responses Litellm sameer nov 3 stable branch (#16963) 2025-11-22 09:35:05 -08:00
router_strategy fix: add None check for litellm_params (#16754) 2025-11-17 19:44:29 -08:00
router_utils [Fix] - Router's Cache: Fix routing for requests with same cacheable prefix but different user messages (#16951) 2025-11-21 19:13:40 -08:00
search [Bug Fix] Exa Search API - ensure request params are sent to Exa AI (#15855) 2025-10-23 11:56:30 -07:00
secret_managers [Feat] Adds IAM role assumption support for AWS Secret Manager (#16887) 2025-11-20 12:38:48 -08:00
types Litellm sameer nov 3 stable branch (#16963) 2025-11-22 09:35:05 -08:00
vector_store_files Vector store files Stable Release (#16643) 2025-11-15 13:00:33 -08:00
vector_stores Fix vector store create issue (#16804) 2025-11-19 16:53:20 -08:00
videos Add Vertex and Gemini Videos API with Cost Tracking + UI support (#16323) 2025-11-08 16:03:51 -08:00
__init__.py [Feat] New LLM Provider - Docker Model Runner (#16948) 2025-11-21 16:09:32 -08:00
_logging.py [Feat] Add support for returning images with gemini/gemini-2.5-flash-image-preview with /chat/completions (#13983) 2025-08-27 16:16:19 -07:00
_redis.py fix: Apply max_connections configuration to Redis async client (#15797) 2025-10-22 09:19:08 -07:00
_service_logger.py [️ Python SDK import] - reduce python sdk import time by .3s (#12140) 2025-06-28 14:57:10 -07:00
_uuid.py Fix: revert fastuuid optional dependency, always use fastuuid in .__uid helper (#14941) 2025-09-26 09:14:20 -07:00
_version.py Virtual key based policies in Aim Guardrails (#9499) 2025-04-01 21:57:23 -07:00
budget_manager.py Squashed commit of the following: (#9709) 2025-04-02 21:24:54 -07:00
constants.py [Perf] Fix bottlenecks degrading realtime endpoint performance (#16670) 2025-11-22 10:01:02 -08:00
cost.json store llm costs in budget manager 2023-09-09 19:11:35 -07:00
cost_calculator.py Fix audio transcription cost tracking (#16478) 2025-11-19 20:29:39 -08:00
exceptions.py Adds support for returning Azure Content Policy error information when exceptions from Azure OpenAI occur (#16231) 2025-11-08 16:04:36 -08:00
main.py Litellm sameer nov 3 stable branch (#16963) 2025-11-22 09:35:05 -08:00
model_prices_and_context_window_backup.json fix bedrock model info 2025-11-22 09:41:15 -08:00
mypy.ini fix mypy 2025-09-27 12:21:32 -07:00
py.typed feature - Types for mypy - #360 2024-05-30 14:14:41 -04:00
router.py Litellm sameer nov 3 stable branch (#16963) 2025-11-22 09:35:05 -08:00
scheduler.py Squashed commit of the following: (#9709) 2025-04-02 21:24:54 -07:00
timeout.py Litellm ruff linting enforcement (#5992) 2024-10-01 19:44:20 -04:00
utils.py Litellm sameer nov 3 stable branch (#16963) 2025-11-22 09:35:05 -08:00