{"record":{"id":"a219a36f7bc4103c","repo":"mem0ai/mem0","slug":"invalid-token-type","errorCode":null,"errorMessage":"Invalid token type.","messagePattern":"Invalid token type\\.","errorType":"http","errorClass":"HTTPException","httpStatus":401,"severity":"error","filePath":"server/auth.py","lineNumber":119,"sourceCode":"        raise HTTPException(status_code=401, detail=\"Invalid or expired token.\")\n\n\nbearer_scheme = HTTPBearer(auto_error=False)\napi_key_header = APIKeyHeader(name=\"X-API-Key\", auto_error=False)\n\n\ndef _mark_auth_type(request: Request, auth_type: str) -> None:\n    request.state.auth_type = auth_type\n\n\ndef _get_default_user(db: Session) -> User | None:\n    return db.scalar(select(User).order_by(User.created_at.asc()))\n\n\ndef _resolve_user_from_jwt(token: str, db: Session) -> User:\n    payload = decode_token(token)\n    if payload.get(\"type\") != \"access\":\n        raise HTTPException(status_code=401, detail=\"Invalid token type.\")\n    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:","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/server/auth.py#L101-L137","documentation":"Error \"Invalid token type.\" thrown in mem0ai/mem0.","triggerScenarios":"Thrown at server/auth.py:119 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use the correct token type: access tokens for API calls, refresh tokens only for the refresh endpoint."],"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-15T17:31:12.345Z"}