mem0ai/mem0 · error · HTTPException
Invalid API key.
Error message
Invalid API key.
What it means
Error "Invalid API key." thrown in mem0ai/mem0.
Source
Thrown at server/auth.py:141
return user
def _resolve_user_from_api_key(key: str, db: Session) -> User:
prefix = key[:12] if len(key) >= 12 else key
candidates = (
db.execute(select(APIKey).where(APIKey.key_prefix == prefix, APIKey.revoked_at.is_(None))).scalars().all()
)
for candidate in candidates:
if verify_api_key_hash(key, candidate.key_hash):
candidate.last_used_at = datetime.now(timezone.utc)
db.commit()
user = db.get(User, candidate.created_by)
if user is None:
raise HTTPException(status_code=401, detail="API key owner not found.")
return user
raise HTTPException(status_code=401, detail="Invalid API key.")
async def verify_auth(
request: Request,
credentials: HTTPAuthorizationCredentials | None = Depends(bearer_scheme),
x_api_key: str | None = Depends(api_key_header),
) -> User | None:
"""Authenticate via JWT, X-API-Key, or legacy ADMIN_API_KEY. Returns User or None.
A short-lived session is opened only on the branches that query the DB, so no
pooled connection is held for the lifetime of the (possibly long-running) request.
"""
if credentials is not None:
_mark_auth_type(request, "bearer")
with SessionLocal() as db:
return _resolve_user_from_jwt(credentials.credentials, db)
if x_api_key is not None:View on GitHub (pinned to 001c235229)
Solutions
- Check the X-API-Key header value; regenerate the API key if it was revoked or mistyped.
When it happens
Trigger: Thrown at server/auth.py:141 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/500f6f7565a5f1e0.
Report an issue: GitHub.