mem0ai/mem0 · error · APIError

Bad request to ${path}: ${detail}

Error message

Bad request to ${path}: ${detail}

What it means

require_auth is the stricter variant of verify_auth: it must produce a non-None User. When authentication used ADMIN_API_KEY or AUTH_DISABLED (paths that return None), it falls back to the first user in the users table; if that table is empty, no default user exists and the request fails with 401 'Authentication required.'

Source

Thrown at cli/node/src/backend/platform.ts:83

		const resp = await fetch(url, fetchOpts);

		if (resp.status === 401) {
			throw new AuthError();
		}
		if (resp.status === 404) {
			throw new NotFoundError(path);
		}
		if (resp.status === 400) {
			let detail: string;
			try {
				const body = (await resp.json()) as Record<string, unknown>;
				detail =
					((body.detail ?? body.message ?? JSON.stringify(body)) as string) ??
					resp.statusText;
			} catch {
				detail = resp.statusText;
			}
			throw new APIError(path, detail);
		}
		if (!resp.ok) {
			let detail: string = resp.statusText;
			try {
				const body = (await resp.json()) as Record<string, unknown>;
				detail = (body.detail ?? body.message ?? resp.statusText) as string;
			} catch {
				/* ignore */
			}
			throw new Error(`HTTP ${resp.status}: ${detail}`);
		}
		if (resp.status === 204) {
			return {};
		}

		const data = await resp.json();

		// Pull the unclaimed-Agent-Mode notice out of the body (or the header

View on GitHub (pinned to 001c235229)

Solutions

  1. Register the first admin account at http://<host>:3000/setup (POST /auth/register) so the users table is non-empty.
  2. Prefer a real Bearer/API-key login over ADMIN_API_KEY/AUTH_DISABLED for endpoints that need a User identity.
  3. If the database was wiped, re-run onboarding to recreate the default user.

Example fix

# before
# AUTH_DISABLED=true in .env, users table empty
curl http://localhost:3000/api-keys  # -> 401 Authentication required.

# after
curl -X POST http://localhost:3000/auth/register -H 'Content-Type: application/json' \
  -d '{"name":"admin","email":"admin@example.com","password":"longpassword"}'
# then use the returned JWT
Defensive patterns

Strategy: validation

Validate before calling

status = requests.get(f"{BASE}/auth/setup-status").json()
if status["needsSetup"]:
    raise RuntimeError("Users table empty: complete /setup before using admin-key/disabled-auth endpoints")

Prevention

When it happens

Trigger: Calling an endpoint guarded by require_auth with ADMIN_API_KEY or AUTH_DISABLED=true while the users table is completely empty (nobody has completed /setup). Also hit after a database wipe that removed users but kept the env configuration.

Common situations: Developer sets AUTH_DISABLED=true expecting open access, but endpoints requiring a real User still 401 because no admin was ever registered; fresh Docker deployment with ADMIN_API_KEY set but /setup never visited; database volume recreated empty while old env vars persisted.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/d0d31cc3e26ccead. Report an issue: GitHub.