Skip to content

Commit

Permalink
fix(proxy_server.py): add support for setting master key via .env
Browse files Browse the repository at this point in the history
  • Loading branch information
krrishdholakia committed Jan 3, 2024
1 parent ef8f1ac commit 14e5018
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
22 changes: 22 additions & 0 deletions docker/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
############
# Secrets
# YOU MUST CHANGE THESE BEFORE GOING INTO PRODUCTION
############

LITELLM_MASTER_KEY="sk-1234"

############
# Database - You can change these to any PostgreSQL database that has logical replication enabled.
############

# LITELLM_DATABASE_URL="your-postgres-db-url"


############
# User Auth - SMTP server details for email-based auth for users to create keys
############

# SMTP_HOST = "fake-mail-host"
# SMTP_USERNAME = "fake-mail-user"
# SMTP_PASSWORD="fake-mail-password"
# SMTP_SENDER_EMAIL="fake-sender-email"
3 changes: 3 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# LiteLLM Docker

This is a minimal Docker Compose setup for self-hosting LiteLLM.
8 changes: 6 additions & 2 deletions litellm/proxy/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ async def user_api_key_auth(
def prisma_setup(database_url: Optional[str]):
global prisma_client, proxy_logging_obj, user_api_key_cache

if database_url is not None:
if (
database_url is not None and prisma_client is None
): # don't re-initialize prisma client after initial init
try:
prisma_client = PrismaClient(
database_url=database_url, proxy_logging_obj=proxy_logging_obj
Expand Down Expand Up @@ -663,7 +665,9 @@ def load_router_config(router: Optional[litellm.Router], config_file_path: str):
## COST TRACKING ##
cost_tracking()
### MASTER KEY ###
master_key = general_settings.get("master_key", None)
master_key = general_settings.get(
"master_key", litellm.get_secret("LITELLM_MASTER_KEY", None)
)
if master_key and master_key.startswith("os.environ/"):
master_key = litellm.get_secret(master_key)
### CUSTOM API KEY AUTH ###
Expand Down
9 changes: 5 additions & 4 deletions litellm/proxy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,11 @@ async def _cache_user_row(user_id: str, cache: DualCache, db: PrismaClient):
response = cache.get_cache(key=cache_key)
if response is None: # Cache miss
user_row = await db.get_data(user_id=user_id)
cache_value = user_row.model_dump_json()
cache.set_cache(
key=cache_key, value=cache_value, ttl=600
) # store for 10 minutes
if user_row is not None:
cache_value = user_row.model_dump_json()
cache.set_cache(
key=cache_key, value=cache_value, ttl=600
) # store for 10 minutes
return


Expand Down

0 comments on commit 14e5018

Please sign in to comment.