mem0ai/mem0 · error · ValueError

org_id and project_id must be set to access project operatio

Error message

org_id and project_id must be set to access project operations

What it means

Project operations in the Mem0 hosted client require BOTH an org_id and a project_id to be configured on the client. _validate_org_project() is the shared guard invoked by project-scoped methods, and it raises ValueError when either identifier is missing. This fails client-side before any network call.

Source

Thrown at mem0/client/project.py:83

    @property
    def project_id(self) -> Optional[str]:
        """Get the project ID."""
        return self.config.project_id

    @property
    def user_email(self) -> Optional[str]:
        """Get the user email."""
        return self.config.user_email

    def _validate_org_project(self) -> None:
        """
        Validate that both org_id and project_id are set.

        Raises:
            ValueError: If org_id or project_id are not set.
        """
        if not (self.config.org_id and self.config.project_id):
            raise ValueError("org_id and project_id must be set to access project operations")

    def _prepare_params(self, kwargs: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
        """
        Prepare query parameters for API requests.

        Args:
            kwargs: Additional keyword arguments.

        Returns:
            Dictionary containing prepared parameters.

        Raises:
            ValueError: If org_id or project_id validation fails.
        """
        if kwargs is None:
            kwargs = {}

        # Add org_id and project_id if available

View on GitHub (pinned to 001c235229)

Solutions

  1. Construct the client with both identifiers: MemoryClient(api_key=..., org_id=..., project_id=...)
  2. Set the MEM0_ORG_ID and MEM0_PROJECT_ID environment variables if the client reads config from env
  3. Retrieve your org/project IDs from the Mem0 platform dashboard before instantiating the client

Example fix

# before
client = MemoryClient(api_key=API_KEY, project_id="p1")
client.project.get()

# after
client = MemoryClient(api_key=API_KEY, org_id="my-org", project_id="p1")
client.project.get()
Defensive patterns

Strategy: validation

Validate before calling

if not (org_id and project_id):
    raise ConfigError("project operations require both org_id and project_id")
client = MemoryClient(api_key=API_KEY, org_id=org_id, project_id=project_id)

Type guard

def can_use_project_ops(cfg) -> bool:
    return bool(getattr(cfg, "org_id", None) and getattr(cfg, "project_id", None))

Try / catch

try:
    client.project.get()
except ValueError as e:
    if "org_id and project_id" in str(e):
        raise ConfigError("set MEM0_ORG_ID and MEM0_PROJECT_ID") from e
    raise

Prevention

When it happens

Trigger: Instantiating a project client with only org_id (or only project_id) and then calling project-scoped methods such as project.get(), update(), delete(), list_members(), or add_member().

Common situations: Copying example code that constructs the client with an API key only; forgetting that project-level APIs need both IDs while memory APIs need neither; environment variables MEM0_ORG_ID / MEM0_PROJECT_ID not exported in the shell running the script.

Related errors


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