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
add example custom
Ishaan Jaffe1e1e2e566ca
diff --git a/litellm/proxy/example_config_yaml/custom_auth.py b/litellm/proxy/example_config_yaml/custom_auth.pyindex 6cecf466c10..2726b1c3d16 100644--- a/litellm/proxy/example_config_yaml/custom_auth.py+++ b/litellm/proxy/example_config_yaml/custom_auth.py@@ -1,50 +1,14 @@-from litellm.proxy._types import UserAPIKeyAuth, GenerateKeyRequestfrom fastapi import Request-import os++from litellm.proxy._types import UserAPIKeyAuthasync def user_api_key_auth(request: Request, api_key: str) -> UserAPIKeyAuth:try:- modified_master_key = f"{os.getenv('PROXY_MASTER_KEY')}-1234"- if api_key == modified_master_key:- return UserAPIKeyAuth(api_key=api_key)- raise Exception+ return UserAPIKeyAuth(+ api_key="best-api-key-ever",+ user_id="best-user-id-ever",+ team_id="best-team-id-ever",+ )except:raise Exception---async def generate_key_fn(data: GenerateKeyRequest):- """- Asynchronously decides if a key should be generated or not based on the provided data.-- Args:- data (GenerateKeyRequest): The data to be used for decision making.-- Returns:- bool: True if a key should be generated, False otherwise.- """- # decide if a key should be generated or not- data_json = data.json() # type: ignore-- # Unpacking variables- team_id = data_json.get("team_id")- duration = data_json.get("duration")- models = data_json.get("models")- aliases = data_json.get("aliases")- config = data_json.get("config")- spend = data_json.get("spend")- user_id = data_json.get("user_id")- max_parallel_requests = data_json.get("max_parallel_requests")- metadata = data_json.get("metadata")- tpm_limit = data_json.get("tpm_limit")- rpm_limit = data_json.get("rpm_limit")-- if team_id is not None and len(team_id) > 0:- return {- "decision": True,- }- else:- return {- "decision": True,- "message": "This violates LiteLLM Proxy Rules. No team id provided.",- }diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yamlindex c5f736bacce..708f0e27ca3 100644--- a/litellm/proxy/proxy_config.yaml+++ b/litellm/proxy/proxy_config.yaml@@ -20,4 +20,5 @@ router_settings:enable_tag_filtering: True # 👈 Key Changegeneral_settings:- master_key: sk-1234\ No newline at end of file+ master_key: sk-1234+ custom_auth: example_config_yaml.custom_auth.user_api_key_auth\ No newline at end of file