mem0ai/mem0 · error · APIError
Invalid response format from ping endpoint
Error message
Invalid response format from ping endpoint
What it means
During client initialization, MemoryClient pings `${host}/v1/ping/` and expects a JSON object back. If the parsed response is not an object (null, array, string, number), it throws APIError('Invalid response format from ping endpoint'). This almost always means something other than the Mem0 API answered — a proxy page, an HTML error page, or a misrouted host.
Source
Thrown at mem0-ts/src/client/mem0.ts:292
return Object.fromEntries(
Object.entries(options).filter(([_, v]) => v != null),
);
}
async ping(): Promise<void> {
try {
const response = await this._fetchWithErrorHandling(
`${this.host}/v1/ping/`,
{
method: "GET",
headers: {
Authorization: `Token ${this.apiKey}`,
},
},
);
if (!response || typeof response !== "object") {
throw new APIError("Invalid response format from ping endpoint");
}
if (response.status !== "ok") {
throw new APIError(response.message || "API Key is invalid");
}
const { orgId, projectId, userEmail } = response;
if (orgId) this.organizationId = orgId;
if (projectId) this.projectId = projectId;
if (userEmail) this.telemetryId = userEmail;
} catch (error: any) {
// Pass through structured exceptions and APIError
if (error instanceof MemoryError || error instanceof APIError) {
throw error;
} else {
throw new APIError(
`Failed to ping server: ${error.message || "Unknown error"}`,View on GitHub (pinned to 001c235229)
Solutions
- curl `${host}/v1/ping/` manually and inspect content-type/body — it must be a JSON object.
- Fix config.host to the actual Mem0 API base (default https://api.mem0.ai), no trailing path, correct scheme.
- Configure proxies/ingress to pass through JSON for the API host and return JSON, not HTML, for errors.
- If self-hosting, upgrade to a server build that implements /v1/ping/.
Example fix
// before
const client = new MemoryClient({ apiKey, host: 'https://internal-gw.corp' }); // HTML login page
// after
const client = new MemoryClient({ apiKey, host: 'https://mem0.internal.corp' }); // direct API host Defensive patterns
Strategy: validation
Validate before calling
async function assertPingIsJson(host: string): Promise<void> {
const res = await fetch(`${host}/v1/ping/`);
const ct = res.headers.get('content-type') ?? '';
if (!ct.includes('application/json')) {
throw new Error(`Ping at ${host} returned '${ct}' — host is not the Mem0 API (proxy or wrong URL?)`);
}
}
await assertPingIsJson(configHost); Type guard
const isJsonObject = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
Try / catch
try {
const client = new MemoryClient({ apiKey, host });
await client.users();
} catch (e) {
if ((e as Error).message.includes('Invalid response format from ping')) {
// not the Mem0 API answering — fix host/proxy before retrying; do NOT blind-retry
throw new Error('host misconfigured or proxy intercepting: verify $host/v1/ping/ returns JSON');
}
throw e;
} Prevention
- Health-check the host with curl and confirm content-type: application/json before wiring the client.
- Keep config.host to a bare origin that routes directly to the Mem0 API.
- Configure ingress error pages to return JSON, not HTML.
When it happens
Trigger: config.host pointing at a URL that returns non-JSON (corporate proxy login page, load-balancer 503 HTML, a typo landing on some other service); a server version without /v1/ping/ returning a plain-text 404; CDN interception rewriting the response.
Common situations: Self-hosted deployments behind an ingress that serves HTML error pages; host set with a path prefix or wrong scheme; firewall captive portals in restricted networks.
Related errors
- Failed to ping server: ${error.message || "Unknown error"}
- LiteLLM failed: ${message}
- NET_CONNECT
- HTTP ${resp.status}: ${detail}
- API Key is invalid
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/cb4cd8cb5d769302.
Report an issue: GitHub.