{"record":{"id":"500f6f7565a5f1e0","repo":"mem0ai/mem0","slug":"invalid-api-key","errorCode":null,"errorMessage":"Invalid API key.","messagePattern":"Invalid API key\\.","errorType":"http","errorClass":"HTTPException","httpStatus":401,"severity":"error","filePath":"server/auth.py","lineNumber":141,"sourceCode":"    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:\n            return _resolve_user_from_jwt(credentials.credentials, db)\n\n    if x_api_key is not None:","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/server/auth.py#L123-L159","documentation":"Error \"Invalid API key.\" thrown in mem0ai/mem0.","triggerScenarios":"Thrown at server/auth.py:141 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the X-API-Key header value; regenerate the API key if it was revoked or mistyped."],"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"}