Documentation Index
Fetch the complete documentation index at: https://mintlify.com/BerriAI/litellm/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The LiteLLM proxy provides comprehensive key management endpoints for creating, updating, listing, and deleting API keys with granular access control.
Generate Key
POST /key/generate
Create a new API key.
Request Body
Models this key can access.{"models": ["gpt-4", "gpt-3.5-turbo"]}
Key expiration duration.Examples: "30d", "1h", "permanent"
Custom metadata for the key.
Maximum spending limit for this key in USD.
Requests per minute limit.
Associate key with a team.
Associate key with a user.
Model aliases for this key.{
"aliases": {
"gpt-4": "my-custom-gpt-4-deployment"
}
}
Additional configuration.
Response
Name/identifier for the key.
Example
curl -X POST http://localhost:4000/key/generate \
-H "Authorization: Bearer sk-admin-xxx" \
-H "Content-Type: application/json" \
-d '{
"models": ["gpt-4", "gpt-3.5-turbo"],
"duration": "30d",
"max_budget": 100.0,
"tpm_limit": 100000,
"rpm_limit": 1000,
"metadata": {
"team": "engineering",
"environment": "production"
}
}'
import requests
response = requests.post(
"http://localhost:4000/key/generate",
headers={"Authorization": "Bearer sk-admin-xxx"},
json={
"models": ["gpt-4", "gpt-3.5-turbo"],
"duration": "30d",
"max_budget": 100.0,
"tpm_limit": 100000,
"rpm_limit": 1000
}
)
key_data = response.json()
print(f"New key: {key_data['key']}")
List Keys
GET /key/list
List all API keys.
Query Parameters
Response
Returns array of key objects:
Array of key objects.
Models this key can access.
Total spend for this key.
Example
curl -X GET 'http://localhost:4000/key/list' \
-H "Authorization: Bearer sk-admin-xxx"
import requests
response = requests.get(
"http://localhost:4000/key/list",
headers={"Authorization": "Bearer sk-admin-xxx"}
)
keys = response.json()["keys"]
for key in keys:
print(f"Key: {key['key_name']}, Spend: ${key['spend']:.2f}")
Get Key Info
GET /key/info
Get detailed information about a specific key.
Query Parameters
Response
Example
curl -X GET 'http://localhost:4000/key/info?key=sk-litellm-xxx' \
-H "Authorization: Bearer sk-admin-xxx"
Update Key
POST /key/update
Update an existing API key.
Request Body
Update accessible models.
Example
curl -X POST http://localhost:4000/key/update \
-H "Authorization: Bearer sk-admin-xxx" \
-H "Content-Type: application/json" \
-d '{
"key": "sk-litellm-xxx",
"max_budget": 200.0,
"tpm_limit": 200000
}'
import requests
response = requests.post(
"http://localhost:4000/key/update",
headers={"Authorization": "Bearer sk-admin-xxx"},
json={
"key": "sk-litellm-xxx",
"max_budget": 200.0,
"models": ["gpt-4", "claude-2"]
}
)
Delete Key
POST /key/delete
Delete an API key.
Request Body
Array of keys to delete.{"keys": ["sk-litellm-xxx", "sk-litellm-yyy"]}
Example
curl -X POST http://localhost:4000/key/delete \
-H "Authorization: Bearer sk-admin-xxx" \
-H "Content-Type: application/json" \
-d '{"keys": ["sk-litellm-xxx"]}'
import requests
response = requests.post(
"http://localhost:4000/key/delete",
headers={"Authorization": "Bearer sk-admin-xxx"},
json={"keys": ["sk-litellm-xxx"]}
)
Regenerate Key
POST /key/regenerate
Regenerate a new key value while keeping settings.
Request Body
Response
Example
curl -X POST http://localhost:4000/key/regenerate \
-H "Authorization: Bearer sk-admin-xxx" \
-H "Content-Type: application/json" \
-d '{"key": "sk-litellm-xxx"}'
Block/Unblock Key
POST /key/block
Temporarily block a key.
curl -X POST http://localhost:4000/key/block \
-H "Authorization: Bearer sk-admin-xxx" \
-H "Content-Type: application/json" \
-d '{"key": "sk-litellm-xxx"}'
POST /key/unblock
Unblock a previously blocked key.
curl -X POST http://localhost:4000/key/unblock \
-H "Authorization: Bearer sk-admin-xxx" \
-H "Content-Type: application/json" \
-d '{"key": "sk-litellm-xxx"}'
Complete Example
import requests
import json
BASE_URL = "http://localhost:4000"
ADMIN_KEY = "sk-admin-xxx"
headers = {
"Authorization": f"Bearer {ADMIN_KEY}",
"Content-Type": "application/json"
}
# 1. Create a new key
key_response = requests.post(
f"{BASE_URL}/key/generate",
headers=headers,
json={
"models": ["gpt-4", "gpt-3.5-turbo"],
"duration": "30d",
"max_budget": 100.0,
"tpm_limit": 100000,
"metadata": {"team": "engineering"}
}
)
new_key = key_response.json()["key"]
print(f"Created key: {new_key}")
# 2. Get key info
info_response = requests.get(
f"{BASE_URL}/key/info",
headers=headers,
params={"key": new_key}
)
print(f"Key info: {json.dumps(info_response.json(), indent=2)}")
# 3. Update the key
update_response = requests.post(
f"{BASE_URL}/key/update",
headers=headers,
json={
"key": new_key,
"max_budget": 150.0
}
)
print("Key updated")
# 4. List all keys
list_response = requests.get(
f"{BASE_URL}/key/list",
headers=headers
)
keys = list_response.json()["keys"]
print(f"Total keys: {len(keys)}")
# 5. Delete the key
delete_response = requests.post(
f"{BASE_URL}/key/delete",
headers=headers,
json={"keys": [new_key]}
)
print("Key deleted")