@@ -66,6 +66,50 @@ curl 'http://0.0.0.0:4000/key/generate' \
66
66
--data-raw
' {"models": ["gpt-3.5-turbo", "gpt-4"], "metadata": {"user": "[email protected] "}}'
67
67
```
68
68
69
+ ## 🔁 Scheduled Key Rotations (NEW in v1.77.5)
70
+
71
+ LiteLLM can now rotate ** virtual keys automatically** on a schedule you define.
72
+
73
+ ### How it works
74
+ 1 . When creating a virtual key you set ` rotation_schedule ` – a [ cron expression] ( https://crontab.guru/ ) .
75
+ 2 . LiteLLM stores the schedule in the DB and runs a background job that regenerates the key at the specified time.
76
+ 3 . Existing key string is invalidated; a ** notification webhook** (if configured) is sent with the new key value.
77
+
78
+ ### Create a key with rotation
79
+
80
+ ``` bash
81
+ curl ' http://0.0.0.0:4000/key/generate' \
82
+ -H ' Authorization: Bearer <your-master-key>' \
83
+ -H ' Content-Type: application/json' \
84
+ -d ' {
85
+ "models": ["gpt-4o"],
86
+ "rotation_schedule": "0 0 * * SUN", # rotate every Sunday at 00:00 UTC
87
+ "webhook_url": "https://example.com/key-rotated"
88
+ }'
89
+ ```
90
+
91
+ ### Enable globally via env
92
+
93
+ Set these env vars when starting the proxy:
94
+
95
+ | Variable | Description | Default |
96
+ | ----------| -------------| ---------|
97
+ | ` LITELLM_KEY_ROTATION_ENABLED ` | Enable the rotation worker | ` false ` |
98
+ | ` LITELLM_KEY_ROTATION_CHECK_INTERVAL_SECONDS ` | How often to scan for keys to rotate | ` 86400 ` |
99
+
100
+ ### Webhook payload
101
+
102
+ ``` json
103
+ {
104
+ "event" : " virtual_key.rotated" ,
105
+ "old_key_id" : " sk-abc..." ,
106
+ "new_key" : " sk-def..." ,
107
+ "rotation_time" : " 2025-10-05T00:00:00Z"
108
+ }
109
+ ```
110
+
111
+ If no ` webhook_url ` is provided the new key value is returned in the response of the ` /key/rotate ` REST call instead.
112
+
69
113
## Spend Tracking
70
114
71
115
Get spend per:
0 commit comments