litellm/litellm/proxy
Ishaan Jaff 6486db3646
fix: improve streaming proxy throughput by fixing middleware and logging bottlenecks (#21501)
* fix(middleware): replace BaseHTTPMiddleware with pure ASGI middleware

BaseHTTPMiddleware wraps streaming responses with receive_or_disconnect
per chunk, blocking the event loop and causing severe throughput
degradation under concurrent streaming load (53% of CPU in profiling).

Converts PrometheusAuthMiddleware to a pure ASGI middleware using the
__call__(scope, receive, send) protocol.

* fix(streaming): remove expensive debug logging and optimize usage stripping

- Remove print_verbose calls that format chunk/response Pydantic objects,
  triggering millions of __repr__ calls (8% of CPU in profiling)
- Guard remaining verbose_logger.debug with isEnabledFor(DEBUG) and use
  lazy %s formatting instead of f-strings
- Replace usage stripping round-trip (model_dump + delete + reconstruct)
  with a _usage_stripped flag, deferring exclusion to serialization time

* fix(proxy): remove per-chunk debug log and use _usage_stripped flag

- Remove verbose_proxy_logger.debug that formatted every streaming chunk
- Honor _usage_stripped flag from streaming handler to exclude usage
  during model_dump_json serialization instead of reconstructing objects

* fix(proxy): remove per-chunk debug log in async_data_generator

Remove verbose_proxy_logger.debug that formatted every streaming chunk,
which triggered expensive Pydantic serialization on the hot path.

* fix indentation and add clarifying comment for usage stripping

* fix: guard calculate_total_usage against None usage in chunks

* fix: store chunk copy to preserve usage for calculate_total_usage
2026-02-18 16:16:49 -08:00
..
_experimental Revert "End users - Allow giving end users access to specific mcp servers (#…" (#21461) 2026-02-17 22:49:57 -08:00
agent_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
analytics_endpoints
anthropic_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
auth Revert "End users - Allow giving end users access to specific mcp servers (#…" (#21461) 2026-02-17 22:49:57 -08:00
batches_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
client fix: prompt registry 2026-02-18 00:34:54 +05:30
common_utils fix: remove unused asyncio imports (F401) 2026-02-17 18:54:18 -03:00
config_management_endpoints
container_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
credential_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
custom_hooks
db Revert "fix(pod-lock): make release lock compare-and-delete atomic (#21226)" 2026-02-18 17:24:34 +05:30
discovery_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
example_config_yaml fix: prompt registry 2026-02-18 00:34:54 +05:30
fine_tuning_endpoints
google_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
guardrails Merge pull request #21464 from BerriAI/litellm_sanitise_anthropic_mesages_2 2026-02-18 18:39:11 +05:30
health_check_utils fix: prompt registry 2026-02-18 00:34:54 +05:30
health_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
hooks fix: prompt registry 2026-02-18 00:34:54 +05:30
image_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
management_endpoints fix(proxy): use prisma.Json for JSON fields in _rotate_master_key create_many 2026-02-18 11:36:15 -03:00
management_helpers
middleware fix: improve streaming proxy throughput by fixing middleware and logging bottlenecks (#21501) 2026-02-18 16:16:49 -08:00
ocr_endpoints
openai_evals_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
openai_files_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
pass_through_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
policy_engine fix: prompt registry 2026-02-18 00:34:54 +05:30
prompts fix: prompt registry 2026-02-18 00:34:54 +05:30
public_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
rag_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
rerank_endpoints
response_api_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
response_polling fix: prompt registry 2026-02-18 00:34:54 +05:30
search_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
spend_tracking fixes - showing content filter on failure 2026-02-17 17:57:52 -08:00
swagger
test_prompts
types_utils
ui_crud_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
vector_store_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
vector_store_files_endpoints fix: prompt registry 2026-02-18 00:34:54 +05:30
vertex_ai_endpoints
video_endpoints Revert "Litellm staging 01 15 2026" 2026-01-17 06:31:34 +09:00
__init__.py
_logging.py
_new_new_secret_config.yaml
_new_secret_config.yaml fix: prompt registry 2026-02-18 00:34:54 +05:30
_super_secret_config.yaml fix: prompt registry 2026-02-18 00:34:54 +05:30
_types.py Revert "End users - Allow giving end users access to specific mcp servers (#…" (#21461) 2026-02-17 22:49:57 -08:00
.gitignore
cached_logo.jpg fix: prompt registry 2026-02-18 00:34:54 +05:30
caching_routes.py
common_request_processing.py fix: prompt registry 2026-02-18 00:34:54 +05:30
compliance_checks.py Add compliance checker endpoints + UI panel (#21432) 2026-02-17 18:22:26 -08:00
custom_auth_auto.py
custom_prompt_management.py fix: prompt registry 2026-02-18 00:34:54 +05:30
custom_sso.py fix: prompt registry 2026-02-18 00:34:54 +05:30
custom_validate.py
enterprise
health_check.py
lambda.py
litellm_pre_call_utils.py Revert "End users - Allow giving end users access to specific mcp servers (#…" (#21461) 2026-02-17 22:49:57 -08:00
llamaguard_prompt.txt
logo.jpg
mcp_registry.json fix: prompt registry 2026-02-18 00:34:54 +05:30
mcp_tools.py
model_config.yaml
openapi.json
post_call_rules.py
prisma_migration.py Revert "Fix/prisma schema permission (#19391)" 2026-01-21 17:19:32 +05:30
proxy_cli.py fix: prompt registry 2026-02-18 00:34:54 +05:30
proxy_config.yaml fix: prompt registry 2026-02-18 00:34:54 +05:30
proxy_server.py fix: improve streaming proxy throughput by fixing middleware and logging bottlenecks (#21501) 2026-02-18 16:16:49 -08:00
README.md
route_llm_request.py fix: prompt registry 2026-02-18 00:34:54 +05:30
schema.prisma Revert "End users - Allow giving end users access to specific mcp servers (#…" (#21461) 2026-02-17 22:49:57 -08:00
start.sh
utils.py fix docs and format 2026-02-18 02:49:52 +05:30

litellm-proxy

A local, fast, and lightweight OpenAI-compatible server to call 100+ LLM APIs.

usage

$ pip install litellm
$ litellm --model ollama/codellama 

#INFO: Ollama running on http://0.0.0.0:8000

replace openai base

import openai # openai v1.0.0+
client = openai.OpenAI(api_key="anything",base_url="http://0.0.0.0:8000") # set proxy to base_url
# request sent to model set on litellm proxy, `litellm --model`
response = client.chat.completions.create(model="gpt-3.5-turbo", messages = [
    {
        "role": "user",
        "content": "this is a test request, write a short poem"
    }
])

print(response)

See how to call Huggingface,Bedrock,TogetherAI,Anthropic, etc.


Folder Structure

Routes

  • proxy_server.py - all openai-compatible routes - /v1/chat/completion, /v1/embedding + model info routes - /v1/models, /v1/model/info, /v1/model_group_info routes.
  • health_endpoints/ - /health, /health/liveliness, /health/readiness
  • management_endpoints/key_management_endpoints.py - all /key/* routes
  • management_endpoints/team_endpoints.py - all /team/* routes
  • management_endpoints/internal_user_endpoints.py - all /user/* routes
  • management_endpoints/ui_sso.py - all /sso/* routes