BerriAI/litellm · error · ValueError

Failed to update key got response = None

Error message

Failed to update key got response = None

What it means

Internal ValueError raised after prisma_client.update_data(token=..., data=...) returns None in _process_single_key_update. update_data returns None when the UPDATE matches no row (the token does not exist in the LiteLLM_VerificationToken table) or the Prisma call failed without raising, so the endpoint treats a null response as a failed key update. It surfaces to the caller as a 500-class error from the management endpoint wrapper.

Source

Thrown at litellm/proxy/management_endpoints/key_management_endpoints.py:2378

            _resolve_token_to_update(data=update_key_request, existing_key_row=existing_key_row)
        ),
        data=update_key_request,
        existing_key_row=existing_key_row,
    )

    # Trigger async hook
    asyncio.create_task(
        KeyManagementEventHooks.async_key_updated_hook(
            data=update_key_request,
            existing_key_row=existing_key_row,
            response=response,
            user_api_key_dict=user_api_key_dict,
            litellm_changed_by=litellm_changed_by,
        )
    )

    if response is None:
        raise ValueError("Failed to update key got response = None")

    # Extract and format updated key info
    updated_key_info = response.get("data", {})
    if hasattr(updated_key_info, "model_dump"):
        updated_key_info = updated_key_info.model_dump()
    elif hasattr(updated_key_info, "dict"):
        updated_key_info = updated_key_info.dict()

    updated_key_info.pop("token", None)

    return updated_key_info


async def _validate_mcp_servers_for_key_update(
    data: "UpdateKeyRequest",
    team_obj: Optional["LiteLLM_TeamTableCachedObj"],
    existing_key_row: LiteLLM_VerificationToken,
    prisma_client: PrismaClient | None,

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Confirm the key exists first: GET /key/info?key=<the exact key you pass in the update> — a miss means wrong/deleted token
  2. Use the exact token value returned by /key/generate (respect any key_decode/hashing settings) in the update body's key field
  3. Check the proxy logs for the preceding Prisma error when the key does exist — fix the DB issue (connectivity, permissions, migration state) it reveals
  4. If the key was deleted, regenerate it instead of updating

Example fix

# before
resp = client.post('/key/update', json={'key': 'my-alias', 'max_budget': 5})  # ValueError: Failed to update key got response = None

# after: resolve the real token first
info = client.post('/key/info', json={'key': 'my-alias'})
token = info.json()['keys'][0]['token']
resp = client.post('/key/update', json={'key': token, 'max_budget': 5})
Defensive patterns

Strategy: try-catch

Validate before calling

import requests

def key_exists(base_url, headers, token) -> bool:
    r = requests.post(f'{base_url}/key/info', headers=headers, json={'key': token}, timeout=10)
    return r.ok and r.json().get('keys')

Try / catch

try:
    update = client.post('/key/update', json={'key': token, **changes})
    update.raise_for_status()
except ValueError as e:  # sdk-side
    if 'response = None' in str(e):
        refresh_token_and_retry()  # token stale/unknown: re-fetch from /key/info
    raise

Prevention

When it happens

Trigger: Updating a key whose token string does not exist in the DB table (typo, already deleted key, unhashed/hashed mismatch), or the Prisma UPDATE throwing internally and returning None — called from /key/update or bulk endpoints via _process_single_key_update with update_key_request.key not matching any row.

Common situations: Client passes a key_alias or a partial key instead of the full token; key was deleted concurrently by another admin; DB replica lag or failed migration leaving the row absent; passing the raw key when the row stores the hashed token (or vice versa) so the WHERE token=... matches nothing.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/625fc66e9ad89eee. Report an issue: GitHub.