{"record":{"id":"528fc98a12fc582e","repo":"mem0ai/mem0","slug":"api-key-owner-not-found","errorCode":null,"errorMessage":"API key owner not found.","messagePattern":"API key owner not found\\.","errorType":"http","errorClass":"HTTPException","httpStatus":401,"severity":"error","filePath":"server/auth.py","lineNumber":138,"sourceCode":"    user = db.get(User, payload.get(\"sub\"))\n    if user is None:\n        raise HTTPException(status_code=401, detail=\"User not found.\")\n    return user\n\n\ndef _resolve_user_from_api_key(key: str, db: Session) -> User:\n    prefix = key[:12] if len(key) >= 12 else key\n    candidates = (\n        db.execute(select(APIKey).where(APIKey.key_prefix == prefix, APIKey.revoked_at.is_(None))).scalars().all()\n    )\n\n    for candidate in candidates:\n        if verify_api_key_hash(key, candidate.key_hash):\n            candidate.last_used_at = datetime.now(timezone.utc)\n            db.commit()\n            user = db.get(User, candidate.created_by)\n            if user is None:\n                raise HTTPException(status_code=401, detail=\"API key owner not found.\")\n            return user\n\n    raise HTTPException(status_code=401, detail=\"Invalid API key.\")\n\n\nasync def verify_auth(\n    request: Request,\n    credentials: HTTPAuthorizationCredentials | None = Depends(bearer_scheme),\n    x_api_key: str | None = Depends(api_key_header),\n) -> User | None:\n    \"\"\"Authenticate via JWT, X-API-Key, or legacy ADMIN_API_KEY. Returns User or None.\n\n    A short-lived session is opened only on the branches that query the DB, so no\n    pooled connection is held for the lifetime of the (possibly long-running) request.\n    \"\"\"\n    if credentials is not None:\n        _mark_auth_type(request, \"bearer\")\n        with SessionLocal() as db:","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/server/auth.py#L120-L156","documentation":"Error \"API key owner not found.\" thrown in mem0ai/mem0.","triggerScenarios":"Thrown at server/auth.py:138 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the API key belongs to an existing user; regenerate the key if the owner was removed."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}