mem0ai/mem0 · error · NetworkError

NET_CONNECT

NET_CONNECT

Error message

Connection failed: {str(e)}

What it means

The client-side translation of httpx.ConnectError into NetworkError with error_code NET_CONNECT, produced by the api_error_handler decorator. It means the TCP/TLS connection to the Mem0 API could not be established at all; the message embeds httpx's original error string (e.g. DNS failure, connection refused).

Solutions

  1. Verify network egress to the API host (curl https://api.mem0.ai) from the same environment
  2. Fix any custom base_url typo or remove it to use the default
  3. Set HTTPS_PROXY/HTTP_PROXY if behind a corporate proxy
  4. If offline intentionally, switch to the open-source self-hosted Memory class instead of the hosted client

Example fix

# before
client = MemoryClient(base_url="https://api.mem0.ai/", api_key=API_KEY)  # blocked network

# after
export HTTPS_PROXY=http://proxy.corp:8080
client = MemoryClient(api_key=API_KEY)
Defensive patterns

Strategy: retry

Validate before calling

import socket

try:
    socket.getaddrinfo("api.mem0.ai", 443)
except OSError as e:
    raise RuntimeError(f"cannot reach api.mem0.ai: {e}; check DNS/proxy/egress")

Type guard

def is_connect_error(err) -> bool:
    return getattr(err, "error_code", None) == "NET_CONNECT"

Try / catch

try:
    client.get_all(user_id=uid)
except NetworkError as e:
    if e.error_code == "NET_CONNECT":
        logger.error("no route to API: %s", e.debug_info.get("original_error"))
        raise SystemExit(2)  # config/network problem; retrying won't help
    raise

Prevention

When it happens

Trigger: Any decorated API call when DNS resolution fails, the host is unreachable, a proxy refuses the connection, or TLS handshake fails. Commonly '[Errno -2] Name or service not known' or 'Connection refused' inside the message.

Common situations: Typos or custom base_url overrides; running in sandboxes/containers without DNS or egress; corporate proxies requiring HTTP_PROXY/HTTPS_PROXY env vars; firewall blocking api.mem0.ai; offline development.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/7fa99db74abd10e7. Report an issue: GitHub.

Appendix: source

Thrown at mem0/client/utils.py:79

        status_code=e.response.status_code,
        response_text=response_text,
        details=error_details,
        debug_info=debug_info,
    )


def _handle_request_error(e):
    logger.error(f"Request error occurred: {e}")

    if isinstance(e, httpx.TimeoutException):
        raise NetworkError(
            message=f"Request timed out: {str(e)}",
            error_code="NET_TIMEOUT",
            suggestion="Please check your internet connection and try again",
            debug_info={"error_type": "timeout", "original_error": str(e)},
        )
    elif isinstance(e, httpx.ConnectError):
        raise NetworkError(
            message=f"Connection failed: {str(e)}",
            error_code="NET_CONNECT",
            suggestion="Please check your internet connection and try again",
            debug_info={"error_type": "connection", "original_error": str(e)},
        )
    else:
        raise NetworkError(
            message=f"Network request failed: {str(e)}",
            error_code="NET_GENERIC",
            suggestion="Please check your internet connection and try again",
            debug_info={"error_type": "request", "original_error": str(e)},
        )


def api_error_handler(func):
    """Decorator to handle API errors consistently.

    This decorator catches HTTP and request errors and converts them to

View on GitHub (pinned to 001c235229)