The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge branch 'main' into litellm_support_lakera_config_thresholds
Krish Dholakiac82fc0cac252
diff --cc docs/my-website/docs/proxy/prompt_injection.mdindex faf1e16b6f7,d1e7aa91627..81d76e7bf84--- a/docs/my-website/docs/proxy/prompt_injection.md+++ b/docs/my-website/docs/proxy/prompt_injection.md@@@ -13,9 -13,9 +13,9 @@@ LiteLLM Supports the following methodsUse this if you want to reject /chat, /completions, /embeddings calls that have prompt injection attacks- LiteLLM uses [LakerAI API](https://platform.lakera.ai/) to detect if a request has a prompt injection attack+ LiteLLM uses [LakeraAI API](https://platform.lakera.ai/) to detect if a request has a prompt injection attack-#### Usage+### UsageStep 1 Set a `LAKERA_API_KEY` in your env```diff --cc litellm/model_prices_and_context_window_backup.jsonindex d4985bffd4c,98b0045ae6b..fd46a5cd6bc--- a/litellm/model_prices_and_context_window_backup.json+++ b/litellm/model_prices_and_context_window_backup.json@@@ -2994,17 -3121,19 +3121,28 @@@"input_cost_per_token": 0.000008,"output_cost_per_token": 0.000024,"litellm_provider": "bedrock",- "mode": "chat"+ "mode": "chat",+ "supports_function_calling": true+ },+ "mistral.mistral-large-2407-v1:0": {+ "max_tokens": 8191,+ "max_input_tokens": 128000,+ "max_output_tokens": 8191,+ "input_cost_per_token": 0.000003,+ "output_cost_per_token": 0.000009,+ "litellm_provider": "bedrock",+ "mode": "chat",+ "supports_function_calling": true},+ "mistral.mistral-large-2407-v1:0": {+ "max_tokens": 8191,+ "max_input_tokens": 128000,+ "max_output_tokens": 8191,+ "input_cost_per_token": 0.000003,+ "output_cost_per_token": 0.000009,+ "litellm_provider": "bedrock",+ "mode": "chat"+ },"bedrock/us-west-2/mistral.mixtral-8x7b-instruct-v0:1": {"max_tokens": 8191,"max_input_tokens": 32000,@@@ -3738,17 -3871,21 +3880,30 @@@"input_cost_per_token": 0.00000265,"output_cost_per_token": 0.0000035,"litellm_provider": "bedrock",- "mode": "chat"+ "mode": "chat",+ "supports_function_calling": true,+ "supports_tool_choice": false+ },+ "meta.llama3-1-405b-instruct-v1:0": {+ "max_tokens": 128000,+ "max_input_tokens": 128000,+ "max_output_tokens": 4096,+ "input_cost_per_token": 0.00000532,+ "output_cost_per_token": 0.000016,+ "litellm_provider": "bedrock",+ "mode": "chat",+ "supports_function_calling": true,+ "supports_tool_choice": false},+ "meta.llama3-1-405b-instruct-v1:0": {+ "max_tokens": 128000,+ "max_input_tokens": 128000,+ "max_output_tokens": 4096,+ "input_cost_per_token": 0.00000532,+ "output_cost_per_token": 0.000016,+ "litellm_provider": "bedrock",+ "mode": "chat"+ },"512-x-512/50-steps/stability.stable-diffusion-xl-v0": {"max_tokens": 77,"max_input_tokens": 77,diff --cc litellm/proxy/_new_secret_config.yamlindex b0fed6f14ae,1bf073513b4..1fdcc5e9378--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@@ -1,16 -1,7 +1,7 @@@model_list:- - model_name: "gpt-3.5-turbo"+ - model_name: "*"litellm_params:- model: "gpt-3.5-turbo"+ model: "*"litellm_settings:- guardrails:- - prompt_injection: # your custom name for guardrail- callbacks: ["lakera_prompt_injection"] # litellm callbacks to use- default_on: true # will run on all llm requests when true- callback_args:- lakera_prompt_injection:- category_thresholds: {- "prompt_injection": 0.1,- "jailbreak": 0.1,- }- callbacks: ["lakera_prompt_injection"]++ callbacks: ["lakera_prompt_injection"]diff --cc litellm/proxy/auth/auth_checks.pyindex 7c5356a379f,2d306ceb314..16634388b2d--- a/litellm/proxy/auth/auth_checks.py+++ b/litellm/proxy/auth/auth_checks.py@@@ -373,14 -375,19 +375,25 @@@ async def _cache_team_objectproxy_logging_obj: Optional[ProxyLogging],):key = "team_id:{}".format(team_id)- await user_api_key_cache.async_set_cache(key=key, value=team_table)++ ## CACHE REFRESH TIME!+ team_table.last_refreshed_at = time.time()++ value = team_table.model_dump_json(exclude_unset=True)+ await user_api_key_cache.async_set_cache(key=key, value=value)++ ## UPDATE REDIS CACHE ##+ if proxy_logging_obj is not None:+ await proxy_logging_obj.internal_usage_cache.async_set_cache(+ key=key, value=value+ )+ ## UPDATE REDIS CACHE ##+ if proxy_logging_obj is not None:+ await proxy_logging_obj.internal_usage_cache.async_set_cache(+ key=key, value=team_table+ )+@log_to_opentelemetryasync def get_team_object(@@@ -402,12 -410,18 +416,17 @@@# check if in cachekey = "team_id:{}".format(team_id)-+ cached_team_obj: Optional[LiteLLM_TeamTableCachedObj] = None- cached_team_obj: Optional[LiteLLM_TeamTable] = None## CHECK REDIS CACHE ##- if proxy_logging_obj is not None:- cached_team_obj = await proxy_logging_obj.internal_usage_cache.async_get_cache(- key=key+ if (+ proxy_logging_obj is not None+ and proxy_logging_obj.internal_usage_cache.redis_cache is not None+ ):+ cached_team_obj = (+ await proxy_logging_obj.internal_usage_cache.redis_cache.async_get_cache(+ key=key+ ))if cached_team_obj is None:diff --cc model_prices_and_context_window.jsonindex d4985bffd4c,98b0045ae6b..fd46a5cd6bc--- a/model_prices_and_context_window.json+++ b/model_prices_and_context_window.json@@@ -2994,17 -3121,19 +3121,28 @@@"input_cost_per_token": 0.000008,"output_cost_per_token": 0.000024,"litellm_provider": "bedrock",- "mode": "chat"+ "mode": "chat",+ "supports_function_calling": true+ },+ "mistral.mistral-large-2407-v1:0": {+ "max_tokens": 8191,+ "max_input_tokens": 128000,+ "max_output_tokens": 8191,+ "input_cost_per_token": 0.000003,+ "output_cost_per_token": 0.000009,+ "litellm_provider": "bedrock",+ "mode": "chat",+ "supports_function_calling": true},+ "mistral.mistral-large-2407-v1:0": {+ "max_tokens": 8191,+ "max_input_tokens": 128000,+ "max_output_tokens": 8191,+ "input_cost_per_token": 0.000003,+ "output_cost_per_token": 0.000009,+ "litellm_provider": "bedrock",+ "mode": "chat"+ },"bedrock/us-west-2/mistral.mixtral-8x7b-instruct-v0:1": {"max_tokens": 8191,"max_input_tokens": 32000,@@@ -3738,17 -3871,21 +3880,30 @@@"input_cost_per_token": 0.00000265,"output_cost_per_token": 0.0000035,"litellm_provider": "bedrock",- "mode": "chat"+ "mode": "chat",+ "supports_function_calling": true,+ "supports_tool_choice": false+ },+ "meta.llama3-1-405b-instruct-v1:0": {+ "max_tokens": 128000,+ "max_input_tokens": 128000,+ "max_output_tokens": 4096,+ "input_cost_per_token": 0.00000532,+ "output_cost_per_token": 0.000016,+ "litellm_provider": "bedrock",+ "mode": "chat",+ "supports_function_calling": true,+ "supports_tool_choice": false},+ "meta.llama3-1-405b-instruct-v1:0": {+ "max_tokens": 128000,+ "max_input_tokens": 128000,+ "max_output_tokens": 4096,+ "input_cost_per_token": 0.00000532,+ "output_cost_per_token": 0.000016,+ "litellm_provider": "bedrock",+ "mode": "chat"+ },"512-x-512/50-steps/stability.stable-diffusion-xl-v0": {"max_tokens": 77,"max_input_tokens": 77,