forked from phoenix/litellm-mirror
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]):
|
||||
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 ###
|
||||
|
|
|
@ -579,6 +579,7 @@ 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)
|
||||
if user_row is not None:
|
||||
cache_value = user_row.model_dump_json()
|
||||
cache.set_cache(
|
||||
key=cache_key, value=cache_value, ttl=600
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue