mem0 TypeScript ignores env-specified proxy settings (http_proxy, HTTPS_PROXY) when talking to model providers
Author: Ark-kunCreated Sep 17, 2026Updated Sep 17, 2026
Labelsbugsdk-typescript
Component
TypeScript SDK
Description
Summary
I'm running agents in a container with an egress auth proxy which securely adds tokens to HTTP requests. The proxy is set system-wide via http_proxy and HTTPS_PROXY env variables. (I also set NODE_USE_ENV_PROXY=1, so fetch() uses the proxy automatically.)
I've installed a mem0-based memory plugin for the Pi agent.
mem0 ignores the proxy, calls the API, fails to initialize.
Expected Behavior
I expect mem0 TypeScript to use the proxy specified via the HTTPS_PROXY environment variable. Node's native fetch and undici work correctly.
Actual Behavior
at _Memory._autoInitialize (file:///root/.pi/agent/npm/node_modules/mem0ai/dist/oss/index.mjs:16918:15)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async _Memory._ensureInitialized (file:///root/.pi/agent/npm/node_modules/mem0ai/dist/oss/index.mjs:16943:7)
at async _Memory.getAll (file:///root/.pi/agent/npm/node_modules/mem0ai/dist/oss/index.mjs:18156:5)
at async OSSProvider._init (file:///root/.pi/agent/npm/node_modules/@amaster.ai/pi-memory-mem0/dist/provider.js:520:9)
Error: Mem0 init failed: Failed to auto-detect embedding dimension from provider 'openai'
Environment
- mem0 version: 3.1.7
- Node version: 24
- OS: Linux
How You Verified This
What I Ran
/**
* mem0-focused reproduction: the mem0ai package ignores HTTPS_PROXY and connects
* to the OpenAI API directly.
*
* We stand up a local proxy and point HTTPS_PROXY / HTTP_PROXY at it, then
* initialize mem0's OSS `Memory` with the OpenAI provider (dummy token).
*
* Because `vectorStore.config.dimension` is left unset, mem0's
* `_autoInitialize()` auto-detects the embedding dimension by calling
* `embedder.embed("dimension probe")` — i.e. it hits the OpenAI embeddings API
* during initialization (the very first `add()`/`_ensureInitialized()`), using
* the OpenAI Node SDK (node-fetch). This is where the proxy-ignoring failure
* surfaces in the wild (stack trace through `Memory._autoInitialize`).
*
* If mem0 honored the proxy, our proxy would receive a CONNECT for
* api.openai.com. It does NOT: mem0 attempts a DIRECT TLS connection to
* api.openai.com, so in a proxy-only egress sandbox the call fails with a
* connect/DNS error (or a 401 if direct egress happens to exist) — never
* touching the proxy.
*
* Run: node repro-mem0.mjs
*/
import http from "node:http";
import net from "node:net";
// ---- 1. Local proxy that records every tunnel attempt ------------------------
const proxyHits = [];
const proxy = http.createServer((req, res) => {
proxyHits.push(`REQ ${req.url}`);
res.writeHead(400);
res.end("expected CONNECT");
});
proxy.on("connect", (req, clientSocket) => {
proxyHits.push(`CONNECT ${req.url}`);
// Don't actually forward anywhere (no egress); just refuse cleanly so we can
// observe that the proxy WAS asked to tunnel.
clientSocket.write("HTTP/1.1 502 Bad Gateway\r\n\r\n");
clientSocket.end();
});
await new Promise((r) => proxy.listen(0, "127.0.0.1", r));
const proxyUrl = `http://127.0.0.1:${proxy.address().port}`;
// ---- 2. Point the conventional env vars at our proxy -------------------------
process.env.HTTP_PROXY = proxyUrl;
process.env.HTTPS_PROXY = proxyUrl;
process.env.http_proxy = proxyUrl;
process.env.https_proxy = proxyUrl;
// Isolate from any ambient system proxy so the result is unambiguous.
process.env.NO_PROXY = "";
process.env.no_proxy = "";
console.log("Local proxy listening at:", proxyUrl);
console.log("HTTP_PROXY / HTTPS_PROXY set to the local proxy.\n");
// ---- 3. Initialize mem0 with the OpenAI provider and a dummy token -----------
const { Memory } = await import("mem0ai/oss");
const memory = new Memory({
embedder: {
provider: "openai",
config: { apiKey: "sk-dummy-token-not-real", model: "text-embedding-3-small" },
},
llm: {
provider: "openai",
config: { apiKey: "sk-dummy-token-not-real", model: "gpt-4o-mini" },
},
vectorStore: {
// NOTE: dimension intentionally omitted -> forces _autoInitialize() to probe
// the OpenAI embeddings API to auto-detect it.
provider: "memory",
config: { collectionName: "repro" },
},
disableHistory: true,
});
console.log("mem0 Memory constructed with OpenAI provider (dummy token).");
console.log("Calling memory.add() -> _ensureInitialized() -> _autoInitialize()");
console.log("-> embedder.embed('dimension probe') -> OpenAI embeddings API...\n");
let outcome;
try {
await memory.add("The user loves hiking in the Alps.", { userId: "u1" });
outcome = "add() returned WITHOUT error (unexpected with a dummy token)";
} catch (err) {
const cause = err?.cause?.message || err?.cause?.code || "";
outcome = `add() threw: ${err?.message || err} ${cause ? `| cause: ${cause}` : ""}`;
const frames = String(err?.stack || "")
.split("\n")
.filter((l) => /_autoInitialize|_ensureInitialized|embed|OpenAIEmbedder/.test(l));
if (frames.length) {
console.log("stack (relevant frames):");
for (const f of frames) console.log(" " + f.trim());
console.log();
}
}
// Give any in-flight sockets a moment to surface on the proxy.
await new Promise((r) => setTimeout(r, 300));
console.log("=== RESULT ===");
console.log("outcome :", outcome);
console.log("proxy tunnels :", proxyHits.length ? proxyHits : "(none - proxy was never contacted)");
const usedProxy = proxyHits.some((h) => h.includes("api.openai.com") || h.startsWith("CONNECT"));
console.log("\nProxy respected?:", usedProxy);
proxy.close();
if (!usedProxy) {
console.log(
"BUG REPRODUCED: mem0ai ignored HTTPS_PROXY. It tried to reach\n" +
" api.openai.com DIRECTLY (OpenAI Node SDK / node-fetch does not read the\n" +
" proxy env vars and receives no httpAgent from mem0), so the request\n" +
" failed instead of tunneling through the configured proxy.\n"
);
process.exit(1);
} else {
console.log("Proxy was used (bug not present).");
}
What I Saw
node repro/repro-mem0.mjs
Local proxy listening at: http://127.0.0.1:46653
HTTP_PROXY / HTTPS_PROXY set to the local proxy.
mem0 Memory constructed with OpenAI provider (dummy token).
Calling memory.add() -> _ensureInitialized() -> _autoInitialize()
-> embedder.embed('dimension probe') -> OpenAI embeddings API...
Error: Failed to auto-detect embedding dimension from provider 'openai': 401 Incorrect API key provided: sk-dummy***********real. You can find your API key at https://platform.openai.com/account/api-keys.. Please set 'dimension' in vectorStore.config or 'embeddingDims' in embedder.config explicitly.
at _Memory._autoInitialize (file:///root/workspace/repro/node_modules/mem0ai/dist/oss/index.mjs:16990:15)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async _Memory._ensureInitialized (file:///root/workspace/repro/node_modules/mem0ai/dist/oss/index.mjs:17008:5)
at async _Memory.add (file:///root/workspace/repro/node_modules/mem0ai/dist/oss/index.mjs:17370:5)
at async file:///root/workspace/repro/repro-mem0.mjs:83:3
Error: Failed to auto-detect embedding dimension from provider 'openai': 401 Incorrect API key provided: sk-dummy***********real. You can find your API key at https://platform.openai.com/account/api-keys.. Please set 'dimension' in vectorStore.config or 'embeddingDims' in embedder.config explicitly.
at _Memory._autoInitialize (file:///root/workspace/repro/node_modules/mem0ai/dist/oss/index.mjs:16990:15)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async _Memory._ensureInitialized (file:///root/workspace/repro/node_modules/mem0ai/dist/oss/index.mjs:17015:7)
at async _Memory.add (file:///root/workspace/repro/node_modules/mem0ai/dist/oss/index.mjs:17370:5)
at async file:///root/workspace/repro/repro-mem0.mjs:83:3
stack (relevant frames):
Error: Failed to auto-detect embedding dimension from provider 'openai': 401 Incorrect API key provided: sk-dummy***********real. You can find your API key at https://platform.openai.com/account/api-keys.. Please set 'dimension' in vectorStore.config or 'embeddingDims' in embedder.config explicitly.
at _Memory._autoInitialize (file:///root/workspace/repro/node_modules/mem0ai/dist/oss/index.mjs:16990:15)
at async _Memory._ensureInitialized (file:///root/workspace/repro/node_modules/mem0ai/dist/oss/index.mjs:17015:7)
=== RESULT ===
outcome : add() threw: Failed to auto-detect embedding dimension from provider 'openai': 401 Incorrect API key provided: sk-dummy***********real. You can find your API key at https://platform.openai.com/account/api-keys.. Please set 'dimension' in vectorStore.config or 'embeddingDims' in embedder.config explicitly.
proxy tunnels : (none — proxy was never contacted)
Proxy respected?: false
BUG REPRODUCED: mem0ai ignored HTTPS_PROXY. It tried to reach
api.openai.com DIRECTLY (OpenAI Node SDK / node-fetch does not read the
proxy env vars and receives no httpAgent from mem0), so the request
failed instead of tunneling through the configured proxy.
Why This Is a Bug
What should have happened instead, and what says so: a docs link, a docstring, a test, or the code itself.
What I Ruled Out
Anything you checked that turned out not to be the cause.
AI Assistance
No AI involved
Source: mem0ai/mem0