Skip to main content

LiteLLM Common

This document provides a reference for the modules/LiteLLM_Common Terraform module — the shared application configuration layer consumed by both LiteLLM_CloudRun and LiteLLM_GKE.


1. Overview

LiteLLM Common is the application-specific shared layer for LiteLLM deployments. It is not deployed directly by users; it is called as a child module by LiteLLM CloudRun and LiteLLM GKE.

Responsibilities:

  • Provisions LITELLM_MASTER_KEY and LITELLM_SALT_KEY in Secret Manager.
  • Builds the config output consumed by the Foundation Module (App CloudRun / App GKE).
  • Assembles LiteLLM environment variables including PROXY_BASE_URL, STORE_MODEL_IN_DB, Redis settings, and HOST.
  • Provides the default db-init Cloud Run Job (using postgres:15-alpine) that creates the LiteLLM PostgreSQL database and user when initialization_jobs is left empty.
  • Declares the litellm-data GCS bucket in storage_buckets output.

2. Secrets Provisioned

Secret NameEnv VarPurpose
<prefix>-master-keyLITELLM_MASTER_KEYPrimary admin API key (prefixed sk-). Required for /key/generate and admin operations.
<prefix>-salt-keyLITELLM_SALT_KEYSalt for hashing virtual keys. Do not rotate after virtual keys have been issued.

A time_sleep of 30 seconds is applied after secret creation for Secret Manager replication.


3. Default Database Initialization Job

When initialization_jobs is empty, LiteLLM Common injects a single db-init job:

name:         "db-init"
image: "postgres:15-alpine"
script_path: <LiteLLM_Common>/scripts/db-init.sh
execute_on_apply: true

The db-init.sh script idempotently creates the LiteLLM database and user using the DB_* environment variables injected by the Foundation Module. It connects to Cloud SQL via the Auth Proxy Unix socket.

Override initialization_jobs with a non-empty list to replace this default.


4. Config Output

Key fields in the config output:

FieldValue
container_imageghcr.io/berriai/litellm
image_sourcecustom
container_build_config.enabledtrue
container_port4000
database_typePOSTGRES_15
enable_cloudsql_volumetrue (default)
STORE_MODEL_IN_DB"true"
PROXY_BASE_URLCaller-supplied service URL
REDIS_HOSTInjected when enable_redis = true and redis_host != ""
REDIS_PORTInjected when enable_redis = true
REDIS_PASSWORDInjected when redis_auth != ""

5. Variables

VariableTypeDefaultDescription
project_idstringGCP project ID.
resource_prefixstringPrefix for resource naming.
labelsmap(string){}Labels applied to all resources.
tenant_deployment_idstring'demo'Deployment identifier.
deployment_idstring""Random deployment ID suffix.
regionstring'us-central1'GCP region.
application_namestring'litellm'Application name.
application_versionstring'main-stable'Container image version tag.
display_namestring'LiteLLM AI Gateway'Display name.
descriptionstring'LiteLLM AI Gateway...'Application description.
db_namestring'litellm_db'PostgreSQL database name.
db_userstring'litellm_user'PostgreSQL application user.
cpu_limitstring'2000m'CPU limit.
memory_limitstring'2Gi'Memory limit.
min_instance_countnumber1Minimum instances.
max_instance_countnumber3Maximum instances.
startup_probeobject{ path="/health/readiness", ... }Startup probe configuration.
liveness_probeobject{ path="/health/liveliness", ... }Liveness probe configuration.
environment_variablesmap(string){}Additional env vars merged with LiteLLM defaults.
enable_cloudsql_volumebooltrueInjects Cloud SQL Auth Proxy sidecar.
initialization_jobslist(any)[]Custom jobs. Empty = inject default db-init.
service_urlstring""Service URL for PROXY_BASE_URL.
enable_redisboolfalseEnable Redis response caching.
redis_hoststringnullRedis hostname or IP.
redis_portstring'6379'Redis port.
redis_authstring (sensitive)""Redis AUTH password.
enable_image_mirroringbooltrueMirror image to Artifact Registry.
gcs_volumeslist(object)[]GCS Fuse volumes.

6. Outputs

OutputDescription
configApplication configuration object for the Foundation Module.
secret_idsMap of LITELLM_MASTER_KEY and LITELLM_SALT_KEY → Secret Manager secret IDs.
storage_bucketsList containing the litellm-data bucket definition.