BerriAI/litellm · error · HTTPException

New key must be at least {MINIMUM_CUSTOM_KEY_LENGTH} charact

Error message

New key must be at least {MINIMUM_CUSTOM_KEY_LENGTH} characters long.

What it means

Error "New key must be at least {MINIMUM_CUSTOM_KEY_LENGTH} characters long." thrown in BerriAI/litellm.

Source

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

        )

    report: Final = await check_encryption(prisma_client=prisma_client)
    return {"status": "success", "report": report.as_dict()}


async def get_new_token(data: RegenerateKeyRequest | None) -> str:
    if data and data.new_key is not None:
        # Reject custom key values if disabled by admin
        await _check_custom_key_allowed(data.new_key)
        if not data.new_key.startswith("sk-"):
            raise HTTPException(
                status_code=status.HTTP_400_BAD_REQUEST,
                detail={
                    "error": "New key must start with 'sk-'. This is to distinguish a key hash (used by litellm for logging / internal logic) from the actual key."
                },
            )
        if len(data.new_key) < MINIMUM_CUSTOM_KEY_LENGTH:
            raise HTTPException(
                status_code=status.HTTP_400_BAD_REQUEST,
                detail={"error": f"New key must be at least {MINIMUM_CUSTOM_KEY_LENGTH} characters long."},
            )
        new_token = data.new_key
    else:
        new_token = f"sk-{secrets.token_urlsafe(LENGTH_OF_LITELLM_GENERATED_KEY)}"
    return new_token


async def _insert_deprecated_key(
    prisma_client: "PrismaClient",
    old_token_hash: str,
    new_token_hash: str,
    grace_period: str | None,
) -> None:
    """
    Insert old key into deprecated table so it remains valid during grace period.

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Provide a key at least MINIMUM_CUSTOM_KEY_LENGTH characters long.
  2. Use a randomly generated key of sufficient length, or let the proxy auto-generate one.

When it happens

Trigger: Thrown at litellm/proxy/management_endpoints/key_management_endpoints.py:4614 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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