litellm/litellm/proxy
ryan-crabbe-berri b5fcd859be
fix(guardrails): return 400 not 500 when AIM blocks a request (#30573)
* fix(guardrails): return 400 not 500 when AIM blocks a request

AIM guardrail blocks raised a bare HTTPException whose type and param
serialized as the literal string "None", which broke OpenAI-SDK error
parsing for downstream consumers. Switching AIM to raise a ProxyException
surfaced a second bug: the shared error funnel re-derived the HTTP status
from a nonexistent status_code attribute and downgraded the 400 to a 500.
The funnel now honors an already-normalized ProxyException rather than
rebuilding it, and ProxyException is excluded from llm_exceptions alerting
so a content-policy block no longer pages on-call as an LLM API failure

Resolves LIT-3751

* fix(guardrails): route all AIM rejection paths through ProxyException

The block-action fix left two AIM rejection paths raising a bare
HTTPException: the multimodal anonymize rejection and the output-side
block. Both serialized type and param as the literal string "None", the
same malformed shape the block fix removed. Funnel all three through a
shared _rejection helper so they return a conformant OpenAI error body.
The output block carries content_policy_violation; the multimodal
rejection stays a plain invalid_request_error because it is a usage
error, not a policy violation

Resolves LIT-3751

* fix(guardrails): record AIM ProxyException blocks in failure logs

Switching AIM blocks from HTTPException to ProxyException made
_is_proxy_only_llm_api_error return False for them, so
_handle_logging_proxy_only_error was skipped and the blocked prompt was
dropped from the configured failure loggers. Classify ProxyException as a
proxy-only error alongside HTTPException so guardrail blocks are recorded
again, matching the prior behavior. The llm_exceptions alert suppression
is a separate check and stays in place

Resolves LIT-3751

* style(guardrails): use str | None over Optional[str] in AIM _rejection

* style(guardrails): collapse AIM _rejection signature per black
2026-06-16 18:56:14 -07:00
..
_experimental chore: litellm oss staging160626 (#30527) 2026-06-16 18:23:13 -07:00
a2a feat(a2a): well-known agent-card discovery + LangGraph Platform mode (#28860) 2026-05-29 20:50:42 -07:00
agent_endpoints chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
analytics_endpoints fix(spend): session-TZ-independent date filtering for spend/error log queries 2026-04-10 17:04:52 -07:00
anthropic_endpoints ci(lint): add blanket-noqa, dataclass-default, and unused-noqa Ruff rules (#30516) 2026-06-16 12:07:22 -07:00
auth chore: litellm oss staging160626 (#30527) 2026-06-16 18:23:13 -07:00
batches_endpoints chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
client feat(cli): per-agent lite claude / codex / opencode commands that wrap coding agents through the proxy (#29850) 2026-06-10 13:52:26 -07:00
common_utils chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
config_management_endpoints build(deps-dev): bump black to 26.3.1 and apply formatting (#28525) 2026-05-21 17:24:18 -07:00
container_endpoints feat(litellm): add models and repository layers (#29686) 2026-06-06 20:59:33 -07:00
credential_endpoints feat(litellm): add models and repository layers (#29686) 2026-06-06 20:59:33 -07:00
custom_hooks style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
db chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
discovery_endpoints chore: litellm oss staging160626 (#30527) 2026-06-16 18:23:13 -07:00
example_config_yaml Extend the record/replay proxy to chat, embeddings, moderations, rerank, and Anthropic (#29847) 2026-06-06 14:33:42 -07:00
fine_tuning_endpoints style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
google_endpoints chore: litellm oss staging160626 (#30527) 2026-06-16 18:23:13 -07:00
guardrails fix(guardrails): return 400 not 500 when AIM blocks a request (#30573) 2026-06-16 18:56:14 -07:00
health_check_utils feat(proxy): skip disable_background_health_check models on GET /health when flag set (#27716) 2026-05-13 09:49:05 -07:00
health_endpoints chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
hooks chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
image_endpoints fix(proxy): extend response headers hook to streaming, TTS, image gen, and pass-through (#24232) 2026-06-09 22:10:23 +02:00
management_endpoints chore: litellm oss staging160626 (#30527) 2026-06-16 18:23:13 -07:00
management_helpers feat(litellm): add models and repository layers (#29686) 2026-06-06 20:59:33 -07:00
memory feat(litellm): add models and repository layers (#29686) 2026-06-06 20:59:33 -07:00
middleware fix(proxy): point /metrics 401 at the opt-out flag 2026-05-08 18:09:14 -07:00
ocr_endpoints Litellm oss staging 04 21 2026 2 (#26569) 2026-05-20 21:25:19 -07:00
openai_evals_endpoints style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
openai_files_endpoints chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
pass_through_endpoints chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
policy_engine fix(guardrails): run pre_call hook once for model-level guardrails (#30543) 2026-06-16 11:17:03 -07:00
prompts feat(litellm): add models and repository layers (#29686) 2026-06-06 20:59:33 -07:00
public_endpoints chore: litellm oss staging160626 (#30527) 2026-06-16 18:23:13 -07:00
rag_endpoints feat(litellm): add models and repository layers (#29686) 2026-06-06 20:59:33 -07:00
realtime_endpoints feat: litellm oss 110626 (#30202) 2026-06-11 22:30:26 -07:00
rerank_endpoints
response_api_endpoints Litellm websocket improvements (#29563) 2026-06-03 11:48:35 -07:00
response_polling chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
search_endpoints fix(proxy): self-heal startup/reload prisma reads on engine disconnect (#28803) 2026-06-10 20:16:58 +02:00
shutdown feat(proxy): native /health/drain preStop hook for graceful shutdown (#29439) 2026-06-02 16:30:44 -07:00
spend_tracking chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
swagger
test_prompts
types_utils fix(types_utils): drop opt-in env from remote-module runtime gate 2026-05-13 02:52:14 +00:00
ui_crud_endpoints feat(ui): add admin flag to disable in-product UI nudges for everyone (#29796) 2026-06-09 17:45:42 -07:00
vector_store_endpoints feat(litellm): add models and repository layers (#29686) 2026-06-06 20:59:33 -07:00
vector_store_files_endpoints Title: fix(proxy): resolve vector store file list credentials from team deployments (#29739) 2026-06-06 12:36:05 -07:00
vertex_ai_endpoints build(deps-dev): bump black to 26.3.1 and apply formatting (#28525) 2026-05-21 17:24:18 -07:00
video_endpoints [Staging] - Ishaan March 17th (#23903) 2026-03-18 15:09:01 -07:00
workflows feat(proxy): durable agent workflow run tracking via /v1/workflows/runs (#26793) 2026-04-29 17:12:18 -07:00
.gitignore
__init__.py
_lazy_features.py feat(a2a): well-known agent-card discovery + LangGraph Platform mode (#28860) 2026-05-29 20:50:42 -07:00
_lazy_openapi_snapshot.json Litellm oss staging 1 (#28337) 2026-05-20 17:27:03 -07:00
_lazy_openapi_snapshot.py [Fix] Proxy: Repair Stale HTTP_METHODS Reference In Lazy OpenAPI Snapshot 2026-05-01 15:11:56 -07:00
_logging.py
_new_new_secret_config.yaml
_new_secret_config.yaml Litellm krrish staging 04 20 2026 (#26138) 2026-04-20 16:22:12 -07:00
_super_secret_config.yaml fix: prompt registry 2026-02-18 00:34:54 +05:30
_types.py feat(proxy): add verification_uri_complete to CLI SSO device flow (#30571) 2026-06-16 17:23:37 -07:00
cached_logo.jpg fix: prompt registry 2026-02-18 00:34:54 +05:30
caching_routes.py Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
common_request_processing.py fix(guardrails): return 400 not 500 when AIM blocks a request (#30573) 2026-06-16 18:56:14 -07:00
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 style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
custom_validate.py
dd_span_tagger.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
enterprise
health_check.py Litellm agent oss staging 05 11 2026 (#27733) 2026-05-13 14:09:12 -07:00
lambda.py
litellm_pre_call_utils.py chore: litellm oss staging160626 (#30527) 2026-06-16 18:23:13 -07:00
llamaguard_prompt.txt
logo.jpg
mcp_registry.json fix(mcp): default Linear MCP registry entry to streamable HTTP (#30396) 2026-06-13 14:45:47 -07:00
mcp_tools.py
model_config.yaml
openapi.json
openapi_registry.json feat(ui): OpenAPI MCP server support with popular API quick-picker (#23200) 2026-03-10 13:59:52 -07:00
post_call_rules.py ci(lint): add blanket-noqa, dataclass-default, and unused-noqa Ruff rules (#30516) 2026-06-16 12:07:22 -07:00
prisma_migration.py
prometheus_cleanup.py Add Prometheus child_exit cleanup for gunicorn workers 2026-02-27 16:11:15 -08:00
proxy_cli.py chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
proxy_config.yaml fix: prompt registry 2026-02-18 00:34:54 +05:30
proxy_server.py chore: litellm oss staging160626 (#30527) 2026-06-16 18:23:13 -07:00
README.md build: migrate packaging, CI, and Docker from Poetry to uv (#25007) 2026-04-09 11:46:23 -07:00
route_llm_request.py chore(lint): remove PLR0915 too-many-statements ruff rule (#30574) 2026-06-16 16:52:49 -07:00
schema.prisma feat(mcp): per-server env vars with global + per-user scopes (#28917) 2026-06-05 20:15:11 -07:00
start.sh
utils.py fix(guardrails): return 400 not 500 when AIM blocks a request (#30573) 2026-06-16 18:56:14 -07:00

litellm-proxy

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

usage

$ uv tool 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