BerriAI/litellm · error · ValueError
User doesn't exist in db. 'user_id'={user_id}. Create user v
Error message
User doesn't exist in db. 'user_id'={user_id}. Create user via `/user/new` call. Got error - {e} What it means
Raised by get_user_object when the underlying DB lookup for user_id throws (typically record not found); the failure is wrapped in a ValueError telling you the key references a user that is not in LiteLLM_UserTable, with instructions to create it via /user/new. The original exception text is appended for diagnosis.
Source
Thrown at litellm/proxy/auth/auth_checks.py:2215
# save the user object to cache
await user_api_key_cache.async_set_cache(
key=user_id,
value=_response,
model_type=LiteLLM_UserTable,
ttl=get_management_object_ttl(user_api_key_cache),
)
# save to db access time
_update_last_db_access_time(
key=db_access_time_key,
value=response_dict,
last_db_access_time=last_db_access_time,
)
return _response
except Exception as e: # if user not in db
_log_budget_lookup_failure("user", e)
raise ValueError(
f"User doesn't exist in db. 'user_id'={user_id}. Create user via `/user/new` call. Got error - {e}"
)
async def _cache_management_object(
key: str,
value: BaseModel | Mapping[str, object],
user_api_key_cache: UserApiKeyCache,
proxy_logging_obj: ProxyLogging | None,
*,
model_type: type[BaseModel],
):
"""
Persist management objects via ``UserApiKeyCache`` (in-memory + optional Redis).
``UserApiKeyCache`` serializes with ``model_type`` so Redis and in-memory stay aligned.
"""
await user_api_key_cache.async_set_cache(View on GitHub (pinned to 77b7c6c40c)
Solutions
- Create the missing user: POST /user/new with the same user_id
- Or rebind the key to an existing user via /key/update
- Audit for other orphaned keys pointing at deleted users
Example fix
# before: key generated for a user that was never created
curl -X POST /key/generate -d '{"user_id": "user-123"}' # user-123 missing
# after: create the user first
curl -X POST /user/new -H "Authorization: Bearer sk-admin" -d '{"user_id": "user-123"}'
curl -X POST /key/generate -H "Authorization: Bearer sk-admin" -d '{"user_id": "user-123"}' Defensive patterns
Strategy: validation
Validate before calling
# provisioning script: create user before key
import requests
def ensure_user(proxy_url, admin_key, user_id):
resp = requests.post(
f"{proxy_url}/user/new",
headers={"Authorization": f"Bearer {admin_key}"},
json={"user_id": user_id},
)
resp.raise_for_status()
ensure_user(proxy_url, admin_key, "user-123")
# then create the key bound to user-123 Try / catch
try:
resp = client.chat.completions.create(**payload)
except Exception as e:
if "User doesn't exist in db" in str(e):
raise RuntimeError("orphaned key: user row missing - create via /user/new") from e
raise Prevention
- Order provisioning: /user/new first, then /key/generate with user_id
- When deleting users, revoke their keys in the same operation
- After DB restores, run an audit that every key's user_id exists
When it happens
Trigger: A virtual key created with a user_id that has no corresponding user row (deleted via /user/delete, never created, or DB reset while keys survived); provisioning scripts that create keys before users.
Common situations: Users cleaned up during GDPR-style deletion leaving orphaned keys; database wiped/restored without the user table; typo'd user_id when generating keys via the API.
Related errors
- Skill not found: {skill_id}
- Plugin '{plugin_name}' not found
- No keys found for team {data.team_id}
- Key not found in team {data.team_id}
- not_found_error
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/d3f203b595a45b4d.
Report an issue: GitHub.