{"record":{"id":"cb4cd8cb5d769302","repo":"mem0ai/mem0","slug":"invalid-response-format-from-ping-endpoint","errorCode":null,"errorMessage":"Invalid response format from ping endpoint","messagePattern":"Invalid response format from ping endpoint","errorType":"http","errorClass":"APIError","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/client/mem0.ts","lineNumber":292,"sourceCode":"    return Object.fromEntries(\n      Object.entries(options).filter(([_, v]) => v != null),\n    );\n  }\n\n  async ping(): Promise<void> {\n    try {\n      const response = await this._fetchWithErrorHandling(\n        `${this.host}/v1/ping/`,\n        {\n          method: \"GET\",\n          headers: {\n            Authorization: `Token ${this.apiKey}`,\n          },\n        },\n      );\n\n      if (!response || typeof response !== \"object\") {\n        throw new APIError(\"Invalid response format from ping endpoint\");\n      }\n\n      if (response.status !== \"ok\") {\n        throw new APIError(response.message || \"API Key is invalid\");\n      }\n\n      const { orgId, projectId, userEmail } = response;\n\n      if (orgId) this.organizationId = orgId;\n      if (projectId) this.projectId = projectId;\n      if (userEmail) this.telemetryId = userEmail;\n    } catch (error: any) {\n      // Pass through structured exceptions and APIError\n      if (error instanceof MemoryError || error instanceof APIError) {\n        throw error;\n      } else {\n        throw new APIError(\n          `Failed to ping server: ${error.message || \"Unknown error\"}`,","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/client/mem0.ts#L274-L310","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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/."],"exampleFix":"// before\nconst client = new MemoryClient({ apiKey, host: 'https://internal-gw.corp' }); // HTML login page\n\n// after\nconst client = new MemoryClient({ apiKey, host: 'https://mem0.internal.corp' }); // direct API host","handlingStrategy":"validation","validationCode":"async function assertPingIsJson(host: string): Promise<void> {\n  const res = await fetch(`${host}/v1/ping/`);\n  const ct = res.headers.get('content-type') ?? '';\n  if (!ct.includes('application/json')) {\n    throw new Error(`Ping at ${host} returned '${ct}' — host is not the Mem0 API (proxy or wrong URL?)`);\n  }\n}\n\nawait assertPingIsJson(configHost);","typeGuard":"const isJsonObject = (v: unknown): v is Record<string, unknown> =>\n  typeof v === 'object' && v !== null && !Array.isArray(v);","tryCatchPattern":"try {\n  const client = new MemoryClient({ apiKey, host });\n  await client.users();\n} catch (e) {\n  if ((e as Error).message.includes('Invalid response format from ping')) {\n    // not the Mem0 API answering — fix host/proxy before retrying; do NOT blind-retry\n    throw new Error('host misconfigured or proxy intercepting: verify $host/v1/ping/ returns JSON');\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["network","proxy","ping","response-format"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}