Skip to main content

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
array
Models this key can access.
{"models": ["gpt-4", "gpt-3.5-turbo"]}
duration
string
Key expiration duration.Examples: "30d", "1h", "permanent"
metadata
object
Custom metadata for the key.
max_budget
number
Maximum spending limit for this key in USD.
tpm_limit
integer
Tokens per minute limit.
rpm_limit
integer
Requests per minute limit.
team_id
string
Associate key with a team.
user_id
string
Associate key with a user.
aliases
object
Model aliases for this key.
{
  "aliases": {
    "gpt-4": "my-custom-gpt-4-deployment"
  }
}
config
object
Additional configuration.
permissions
object
Key permissions.

Response

key
string
The generated API key.
key_name
string
Name/identifier for the key.
expires
string
Expiration timestamp.
user_id
string
Associated user ID.
team_id
string
Associated team ID.

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

user_id
string
Filter by user ID.
team_id
string
Filter by team ID.

Response

Returns array of key objects:
keys
array
Array of key objects.

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

key
string
required
The API key to query.

Response

key
string
The API key (masked).
models
array
Models accessible.
spend
number
Total spend.
max_budget
number
Budget limit.
metadata
object
Custom metadata.
tpm_limit
integer
TPM limit.
rpm_limit
integer
RPM limit.

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

key
string
required
The key to update.
models
array
Update accessible models.
max_budget
number
Update budget limit.
tpm_limit
integer
Update TPM limit.
rpm_limit
integer
Update RPM limit.
metadata
object
Update metadata.

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

keys
array
required
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

key
string
required
The key to regenerate.

Response

key
string
The new API key.

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")

Build docs developers (and LLMs) love