{"record":{"id":"c9d0c0682d841982","repo":"mem0ai/mem0","slug":"org-id-must-be-set-for-organization-level-operatio","errorCode":null,"errorMessage":"org_id must be set for organization-level operations","messagePattern":"org_id must be set for organization-level operations","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/client/project.py","lineNumber":130,"sourceCode":"        Prepare query parameters for organization-level API requests.\n\n        Args:\n            kwargs: Additional keyword arguments.\n\n        Returns:\n            Dictionary containing prepared parameters.\n\n        Raises:\n            ValueError: If org_id is not provided.\n        \"\"\"\n        if kwargs is None:\n            kwargs = {}\n\n        # Add org_id if available\n        if self.config.org_id:\n            kwargs[\"org_id\"] = self.config.org_id\n        else:\n            raise ValueError(\"org_id must be set for organization-level operations\")\n\n        return {k: v for k, v in kwargs.items() if v is not None}\n\n    @abstractmethod\n    def get(self, fields: Optional[List[str]] = None) -> Dict[str, Any]:\n        \"\"\"\n        Get project details.\n\n        Args:\n            fields: List of fields to retrieve\n\n        Returns:\n            Dictionary containing the requested project fields.\n\n        Raises:\n            ValidationError: If the input data is invalid.\n            AuthenticationError: If authentication fails.\n            RateLimitError: If rate limits are exceeded.","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/client/project.py#L112-L148","documentation":"Organization-level operations (listing projects, org metadata) need only org_id, and _prepare_org_params() raises ValueError when it is absent from the client config. This is the org-level counterpart to the org+project guard. It fires client-side before any request is sent.","triggerScenarios":"Calling org-scoped methods such as projects.list()/create() on a client instantiated without org_id (e.g. only api_key, or only project_id).","commonSituations":"Using a memory-only client (api_key + user_id) and then trying to enumerate projects; org_id present in one environment (dashboard scripts) but omitted in the app's config; onboarding flows that list projects before the user has chosen an org.","solutions":["Pass org_id when constructing the client before calling org-level methods","Export MEM0_ORG_ID (or your config equivalent) in the environment running the code","Copy the org ID from the Mem0 platform URL/dashboard and wire it into config"],"exampleFix":"# before\nclient = MemoryClient(api_key=API_KEY)\nclient.projects.create(name=\"demo\")  # ValueError\n\n# after\nclient = MemoryClient(api_key=API_KEY, org_id=\"my-org\")\nclient.projects.create(name=\"demo\")","handlingStrategy":"validation","validationCode":"if not cfg.org_id:\n    raise ConfigError(\"org-level operations require org_id\")\nclient = MemoryClient(api_key=API_KEY, org_id=cfg.org_id)","typeGuard":"def can_use_org_ops(cfg) -> bool:\n    return bool(getattr(cfg, \"org_id\", None))","tryCatchPattern":"try:\n    client.projects.list()\nexcept ValueError as e:\n    if \"org_id must be set\" in str(e):\n        return redirect_to_org_setup()\n    raise","preventionTips":["Fail fast at boot if org-level features are enabled but org_id is missing","Store org_id next to the API key in the same secret/config source"],"tags":["validation","hosted-api","organizations","configuration"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}