* 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 |
||
|---|---|---|
| .. | ||
| _experimental | ||
| agent_endpoints | ||
| analytics_endpoints | ||
| anthropic_endpoints | ||
| auth | ||
| batches_endpoints | ||
| client | ||
| common_utils | ||
| config_management_endpoints | ||
| container_endpoints | ||
| credential_endpoints | ||
| custom_hooks | ||
| db | ||
| discovery_endpoints | ||
| example_config_yaml | ||
| fine_tuning_endpoints | ||
| google_endpoints | ||
| guardrails | ||
| health_check_utils | ||
| health_endpoints | ||
| hooks | ||
| image_endpoints | ||
| management_endpoints | ||
| management_helpers | ||
| middleware | ||
| ocr_endpoints | ||
| openai_evals_endpoints | ||
| openai_files_endpoints | ||
| pass_through_endpoints | ||
| policy_engine | ||
| prompts | ||
| public_endpoints | ||
| rag_endpoints | ||
| rerank_endpoints | ||
| response_api_endpoints | ||
| response_polling | ||
| search_endpoints | ||
| spend_tracking | ||
| swagger | ||
| test_prompts | ||
| types_utils | ||
| ui_crud_endpoints | ||
| vector_store_endpoints | ||
| vector_store_files_endpoints | ||
| vertex_ai_endpoints | ||
| video_endpoints | ||
| __init__.py | ||
| _logging.py | ||
| _new_new_secret_config.yaml | ||
| _new_secret_config.yaml | ||
| _super_secret_config.yaml | ||
| _types.py | ||
| .gitignore | ||
| cached_logo.jpg | ||
| caching_routes.py | ||
| common_request_processing.py | ||
| compliance_checks.py | ||
| custom_auth_auto.py | ||
| custom_prompt_management.py | ||
| custom_sso.py | ||
| custom_validate.py | ||
| enterprise | ||
| health_check.py | ||
| lambda.py | ||
| litellm_pre_call_utils.py | ||
| llamaguard_prompt.txt | ||
| logo.jpg | ||
| mcp_registry.json | ||
| mcp_tools.py | ||
| model_config.yaml | ||
| openapi.json | ||
| post_call_rules.py | ||
| prisma_migration.py | ||
| proxy_cli.py | ||
| proxy_config.yaml | ||
| proxy_server.py | ||
| README.md | ||
| route_llm_request.py | ||
| schema.prisma | ||
| start.sh | ||
| utils.py | ||
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_inforoutes.health_endpoints/-/health,/health/liveliness,/health/readinessmanagement_endpoints/key_management_endpoints.py- all/key/*routesmanagement_endpoints/team_endpoints.py- all/team/*routesmanagement_endpoints/internal_user_endpoints.py- all/user/*routesmanagement_endpoints/ui_sso.py- all/sso/*routes