aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/litellm/proxy/example_config_yaml/custom_auth.py
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/litellm/proxy/example_config_yaml/custom_auth.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are hereHEADmaster
Diffstat (limited to '.venv/lib/python3.12/site-packages/litellm/proxy/example_config_yaml/custom_auth.py')
-rw-r--r--.venv/lib/python3.12/site-packages/litellm/proxy/example_config_yaml/custom_auth.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/litellm/proxy/example_config_yaml/custom_auth.py b/.venv/lib/python3.12/site-packages/litellm/proxy/example_config_yaml/custom_auth.py
new file mode 100644
index 00000000..7d797623
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/litellm/proxy/example_config_yaml/custom_auth.py
@@ -0,0 +1,52 @@
+import os
+
+from fastapi import Request
+
+from litellm.proxy._types import GenerateKeyRequest, UserAPIKeyAuth
+
+
+async 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
+ except Exception:
+ 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")
+ data_json.get("duration")
+ data_json.get("models")
+ data_json.get("aliases")
+ data_json.get("config")
+ data_json.get("spend")
+ data_json.get("user_id")
+ data_json.get("max_parallel_requests")
+ data_json.get("metadata")
+ data_json.get("tpm_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.",
+ }