rohitg00/agentmemory · error · Error

OpenAI API request timed out after ${this.timeoutMs}ms — set

Error message

OpenAI API request timed out after ${this.timeoutMs}ms — set OPENAI_TIMEOUT_MS (or AGENTMEMORY_LLM_TIMEOUT_MS) to raise the bound or check the provider status.

What it means

OpenAIProvider.call wraps its fetch with an AbortController timeout of this.timeoutMs. When the request is aborted (err.name === 'AbortError'), it rethrows this descriptive error naming the timeout and the env vars (OPENAI_TIMEOUT_MS or AGENTMEMORY_LLM_TIMEOUT_MS) that raise the bound. It means the OpenAI endpoint did not respond within the configured window — the error message explicitly suggests raising the timeout or checking provider status.

Source

Thrown at src/providers/openai.ts:119

    // provider (minimax, openrouter, gemini, openrouter-embed, etc.).
    // OPENAI_TIMEOUT_MS keeps its v0.9.17 meaning (OpenAI-scoped alias,
    // takes precedence); when unset we fall through to
    // AGENTMEMORY_LLM_TIMEOUT_MS and finally the 60s default. See #446.
    let response: Response;
    try {
      response = await fetchWithTimeout(
        url,
        {
          method: "POST",
          headers: buildAuthHeaders(this.apiKey, this.isAzure),
          body: JSON.stringify(body),
        },
        this.timeoutMs,
      );
    } catch (err) {
      const aborted = err instanceof Error && err.name === "AbortError";
      if (aborted) {
        throw new Error(
          `OpenAI API request timed out after ${this.timeoutMs}ms — set OPENAI_TIMEOUT_MS (or AGENTMEMORY_LLM_TIMEOUT_MS) to raise the bound or check the provider status.`,
        );
      }
      throw err;
    }

    if (!response.ok) {
      const text = await response.text();
      throw new Error(`OpenAI API error (${response.status}): ${text}`);
    }

    const data = (await response.json()) as {
      choices?: Array<{
        message?: { content?: string; reasoning?: string; reasoning_content?: string };
      }>;
    };
    const message = data.choices?.[0]?.message;
    const content = message?.content;

View on GitHub (pinned to e04ba88819)

Solutions

  1. Set OPENAI_TIMEOUT_MS (or AGENTMEMORY_LLM_TIMEOUT_MS) to a larger value, e.g. 120000
  2. Check OpenAI status page for ongoing incidents
  3. Reduce prompt size / chunk large inputs to shorten response time
  4. Verify network path (proxy/VPN) isn't stalling the connection
  5. Use a fallback provider (createFallbackProvider) so slow OpenAI calls fail over

Example fix

// before
# default timeout too small for long reasoning responses
npm start

// after
export AGENTMEMORY_LLM_TIMEOUT_MS=180000
npm start
Defensive patterns

Strategy: retry

Validate before calling

const timeout = Number(process.env.OPENAI_TIMEOUT_MS ?? process.env.AGENTMEMORY_LLM_TIMEOUT_MS ?? 60000);
if (!Number.isFinite(timeout) || timeout < 5000) throw new Error('Set OPENAI_TIMEOUT_MS to a sane value');

Try / catch

try {
  return await provider.call(prompt);
} catch (e) {
  if ((e as Error).message.includes('timed out after')) {
    return retryWithBackoff(() => provider.call(prompt), 2);
  }
  throw e;
}

Prevention

When it happens

Trigger: compress() or summarize() calls OpenAIProvider.call(); fetch exceeds timeoutMs (default from OPENAI_TIMEOUT_MS / AGENTMEMORY_LLM_TIMEOUT_MS) and the abort fires; the thrown error's name is exactly 'AbortError'.

Common situations: Long reasoning models (o-series, DeepSeek-style compatible endpoints) taking >60s on big prompts; slow corporate proxies; OpenAI incident/degradation; default timeout too low for very large compress jobs; regionally blocked connections that hang instead of failing fast.

Understand the failure class

Related errors


AI-assisted analysis of rohitg00/agentmemory@e04ba88819 (2026-08-30). Data as JSON: /api/errors/54e8a6c28fb028fa. Report an issue: GitHub.