{"record":{"id":"6fba67f9407dc306","repo":"mem0ai/mem0","slug":"net-timeout","errorCode":"NET_TIMEOUT","errorMessage":"Request timed out: {str(e)}","messagePattern":"Request timed out: (.+?)","errorType":"exception","errorClass":"NetworkError","httpStatus":null,"severity":"error","filePath":"mem0/client/utils.py","lineNumber":72,"sourceCode":"\n        for header in [\"X-RateLimit-Limit\", \"X-RateLimit-Remaining\", \"X-RateLimit-Reset\"]:\n            value = e.response.headers.get(header)\n            if value:\n                debug_info[header.lower().replace(\"-\", \"_\")] = value\n\n    raise create_exception_from_response(\n        status_code=e.response.status_code,\n        response_text=response_text,\n        details=error_details,\n        debug_info=debug_info,\n    )\n\n\ndef _handle_request_error(e):\n    logger.error(f\"Request error occurred: {e}\")\n\n    if isinstance(e, httpx.TimeoutException):\n        raise NetworkError(\n            message=f\"Request timed out: {str(e)}\",\n            error_code=\"NET_TIMEOUT\",\n            suggestion=\"Please check your internet connection and try again\",\n            debug_info={\"error_type\": \"timeout\", \"original_error\": str(e)},\n        )\n    elif isinstance(e, httpx.ConnectError):\n        raise NetworkError(\n            message=f\"Connection failed: {str(e)}\",\n            error_code=\"NET_CONNECT\",\n            suggestion=\"Please check your internet connection and try again\",\n            debug_info={\"error_type\": \"connection\", \"original_error\": str(e)},\n        )\n    else:\n        raise NetworkError(\n            message=f\"Network request failed: {str(e)}\",\n            error_code=\"NET_GENERIC\",\n            suggestion=\"Please check your internet connection and try again\",\n            debug_info={\"error_type\": \"request\", \"original_error\": str(e)},","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/client/utils.py#L54-L90","documentation":"This is the client-side translation of an httpx.TimeoutException into Mem0's structured NetworkError with error_code NET_TIMEOUT. The api_error_handler decorator catches transport-level exceptions from requests and re-raises them as NetworkError with a suggestion and debug_info. The message embeds the underlying httpx exception string.","triggerScenarios":"Any decorated HTTP call (memory add/search/get, project ops) where the HTTP operation exceeds httpx's timeout — default is 5s connect/read in many clients; large batch adds and slow embedding pipelines are typical. httpx.TimeoutException subclasses include ConnectTimeout, ReadTimeout, WriteTimeout, PoolTimeout.","commonSituations":"Bulk-ingesting thousands of memories in one call; slow network or VPN/proxy adding latency; the Mem0 platform briefly slow; timeouts set too low for heavy vector-store workloads.","solutions":["Retry the request — timeouts are often transient (ideally with backoff, and make add() idempotent via run_id/agent_id scoping)","Increase the client timeout passed to MemoryClient (e.g. timeout=60) if you regularly do large batch calls","Split oversized batch payloads into smaller chunks","Check local network/proxy/VPN conditions if timeouts are persistent"],"exampleFix":"# before\nresult = client.add(messages, user_id=\"alice\")  # large batch times out\n\n# after\nclient = MemoryClient(api_key=API_KEY, timeout=60)\nfor chunk in [messages[i:i+100] for i in range(0, len(messages), 100)]:\n    client.add(chunk, user_id=\"alice\")","handlingStrategy":"retry","validationCode":"# Pre-flight sanity (does not guarantee no timeout, but catches obvious issues)\nimport socket, time\nsocket.setdefaulttimeout(5)\nt0 = time.time()\ntry:\n    socket.getaddrinfo(\"api.mem0.ai\", 443)\nexcept OSError:\n    raise RuntimeError(\"no DNS/egress; fix network before retrying API calls\")","typeGuard":"from mem0.exceptions import NetworkError\n\ndef is_timeout(err: NetworkError) -> bool:\n    return getattr(err, \"error_code\", None) == \"NET_TIMEOUT\"","tryCatchPattern":"from mem0.exceptions import NetworkError\n\nfor attempt in range(3):\n    try:\n        result = client.add(messages, user_id=uid)\n        break\n    except NetworkError as e:\n        if e.error_code != \"NET_TIMEOUT\" or attempt == 2:\n            raise\n        time.sleep(2 ** attempt)","preventionTips":["Set an explicit generous timeout on MemoryClient for batch workloads","Chunk large batch_add calls into hundreds (not thousands) of messages","Make retry safe: scope adds with stable run_id/agent_id so duplicates are detectable"],"tags":["network","timeout","httpx","hosted-api"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}