{"record":{"id":"d3f203b595a45b4d","repo":"BerriAI/litellm","slug":"user-doesn-t-exist-in-db-user-id-user-id-cre","errorCode":null,"errorMessage":"User doesn't exist in db. 'user_id'={user_id}. Create user via `/user/new` call. Got error - {e}","messagePattern":"User doesn't exist in db\\. 'user_id'=(.+?)\\. Create user via `/user/new` call\\. Got error - (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/auth/auth_checks.py","lineNumber":2215,"sourceCode":"        # save the user object to cache\n        await user_api_key_cache.async_set_cache(\n            key=user_id,\n            value=_response,\n            model_type=LiteLLM_UserTable,\n            ttl=get_management_object_ttl(user_api_key_cache),\n        )\n\n        # save to db access time\n        _update_last_db_access_time(\n            key=db_access_time_key,\n            value=response_dict,\n            last_db_access_time=last_db_access_time,\n        )\n\n        return _response\n    except Exception as e:  # if user not in db\n        _log_budget_lookup_failure(\"user\", e)\n        raise ValueError(\n            f\"User doesn't exist in db. 'user_id'={user_id}. Create user via `/user/new` call. Got error - {e}\"\n        )\n\n\nasync def _cache_management_object(\n    key: str,\n    value: BaseModel | Mapping[str, object],\n    user_api_key_cache: UserApiKeyCache,\n    proxy_logging_obj: ProxyLogging | None,\n    *,\n    model_type: type[BaseModel],\n):\n    \"\"\"\n    Persist management objects via ``UserApiKeyCache`` (in-memory + optional Redis).\n\n    ``UserApiKeyCache`` serializes with ``model_type`` so Redis and in-memory stay aligned.\n    \"\"\"\n    await user_api_key_cache.async_set_cache(","sourceCodeStart":2197,"sourceCodeEnd":2233,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/auth/auth_checks.py#L2197-L2233","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before: key generated for a user that was never created\ncurl -X POST /key/generate -d '{\"user_id\": \"user-123\"}'  # user-123 missing\n\n# after: create the user first\ncurl -X POST /user/new -H \"Authorization: Bearer sk-admin\" -d '{\"user_id\": \"user-123\"}'\ncurl -X POST /key/generate -H \"Authorization: Bearer sk-admin\" -d '{\"user_id\": \"user-123\"}'","handlingStrategy":"validation","validationCode":"# provisioning script: create user before key\nimport requests\n\ndef ensure_user(proxy_url, admin_key, user_id):\n    resp = requests.post(\n        f\"{proxy_url}/user/new\",\n        headers={\"Authorization\": f\"Bearer {admin_key}\"},\n        json={\"user_id\": user_id},\n    )\n    resp.raise_for_status()\n\nensure_user(proxy_url, admin_key, \"user-123\")\n# then create the key bound to user-123","typeGuard":null,"tryCatchPattern":"try:\n    resp = client.chat.completions.create(**payload)\nexcept Exception as e:\n    if \"User doesn't exist in db\" in str(e):\n        raise RuntimeError(\"orphaned key: user row missing - create via /user/new\") from e\n    raise","preventionTips":["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"],"tags":["user","not-found","db","provisioning","litellm-proxy"],"backgroundTag":"user-record-not-found","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}