mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
fix(proxy_server.py): add support for setting master key via .env
This commit is contained in:
parent
ef8f1acfa4
commit
14e501845f
4 changed files with 36 additions and 6 deletions
22
docker/.env.example
Normal file
22
docker/.env.example
Normal file
|
@ -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
docker/README.md
Normal file
3
docker/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# LiteLLM Docker
|
||||||
|
|
||||||
|
This is a minimal Docker Compose setup for self-hosting LiteLLM.
|
|
@ -306,7 +306,9 @@ async def user_api_key_auth(
|
||||||
def prisma_setup(database_url: Optional[str]):
|
def prisma_setup(database_url: Optional[str]):
|
||||||
global prisma_client, proxy_logging_obj, user_api_key_cache
|
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:
|
try:
|
||||||
prisma_client = PrismaClient(
|
prisma_client = PrismaClient(
|
||||||
database_url=database_url, proxy_logging_obj=proxy_logging_obj
|
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 ##
|
||||||
cost_tracking()
|
cost_tracking()
|
||||||
### MASTER KEY ###
|
### 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/"):
|
if master_key and master_key.startswith("os.environ/"):
|
||||||
master_key = litellm.get_secret(master_key)
|
master_key = litellm.get_secret(master_key)
|
||||||
### CUSTOM API KEY AUTH ###
|
### CUSTOM API KEY AUTH ###
|
||||||
|
|
|
@ -579,10 +579,11 @@ async def _cache_user_row(user_id: str, cache: DualCache, db: PrismaClient):
|
||||||
response = cache.get_cache(key=cache_key)
|
response = cache.get_cache(key=cache_key)
|
||||||
if response is None: # Cache miss
|
if response is None: # Cache miss
|
||||||
user_row = await db.get_data(user_id=user_id)
|
user_row = await db.get_data(user_id=user_id)
|
||||||
cache_value = user_row.model_dump_json()
|
if user_row is not None:
|
||||||
cache.set_cache(
|
cache_value = user_row.model_dump_json()
|
||||||
key=cache_key, value=cache_value, ttl=600
|
cache.set_cache(
|
||||||
) # store for 10 minutes
|
key=cache_key, value=cache_value, ttl=600
|
||||||
|
) # store for 10 minutes
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue