diff --git a/docker/.env.example b/docker/.env.example new file mode 100644 index 000000000..91934506a --- /dev/null +++ b/docker/.env.example @@ -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" \ No newline at end of file diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 000000000..8dbc59d01 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,3 @@ +# LiteLLM Docker + +This is a minimal Docker Compose setup for self-hosting LiteLLM. \ No newline at end of file diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index c6eae23e7..c5249943d 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -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 @@ -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 ### diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index fcc58920d..bb855d9f7 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -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