{"record":{"id":"f84ff552008261c4","repo":"mem0ai/mem0","slug":"org-id-must-be-set-to-create-a-project","errorCode":null,"errorMessage":"org_id must be set to create a project","messagePattern":"org_id must be set to create a project","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/client/project.py","lineNumber":376,"sourceCode":"        \"\"\"\n        Create a new project within the organization.\n\n        Args:\n            name: Name of the project to be created\n            description: Optional description for the project\n\n        Returns:\n            Dictionary containing the created project details.\n\n        Raises:\n            ValidationError: If the input data is invalid.\n            AuthenticationError: If authentication fails.\n            RateLimitError: If rate limits are exceeded.\n            NetworkError: If network connectivity issues occur.\n            ValueError: If org_id is not set.\n        \"\"\"\n        if not self.config.org_id:\n            raise ValueError(\"org_id must be set to create a project\")\n\n        payload = {\"name\": name}\n        if description is not None:\n            payload[\"description\"] = description\n\n        response = self._client.post(\n            f\"/api/v1/orgs/organizations/{self.config.org_id}/projects/\",\n            json=payload,\n        )\n        response.raise_for_status()\n        capture_client_event(\n            \"client.project.create\",\n            self,\n            {\"name\": name, \"description\": description, \"sync_type\": \"sync\"},\n        )\n        return response.json()\n\n    @api_error_handler","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/client/project.py#L358-L394","documentation":"The synchronous project create() posts to /api/v1/orgs/organizations/{org_id}/projects/, which requires an org_id in the URL. If the client config has no org_id, it raises ValueError before making the request. This is the sync twin of the async guard at project.py:700.","triggerScenarios":"Calling `client.projects.create(name=...)` (sync) on a client constructed without org_id. The check is `if not self.config.org_id`, so an empty string also triggers it.","commonSituations":"Onboarding scripts that try to create the first project before any org context is configured; org_id loaded from a settings file that silently returns None; mixing memory-scope and project-scope client usage in one app.","solutions":["Construct the client with org_id before calling projects.create()","Verify the org_id value is a non-empty string (None or \"\" both fail)","Fetch the org ID from the Mem0 dashboard and add it to your config/env"],"exampleFix":"# before\nclient = MemoryClient(api_key=API_KEY)\nclient.projects.create(name=\"demo\")\n\n# after\nclient = MemoryClient(api_key=API_KEY, org_id=\"my-org\")\nclient.projects.create(name=\"demo\")","handlingStrategy":"validation","validationCode":"if not (org_id and org_id.strip()):\n    raise ConfigError(\"projects.create requires a non-empty org_id\")\nclient = MemoryClient(api_key=API_KEY, org_id=org_id)","typeGuard":"def has_org_id(client) -> bool:\n    return bool(getattr(getattr(client, \"config\", None), \"org_id\", None))","tryCatchPattern":"try:\n    client.projects.create(name=name)\nexcept ValueError as e:\n    if \"org_id must be set to create\" in str(e):\n        raise ConfigError(\"configure org_id before provisioning projects\") from e\n    raise","preventionTips":["Provision org context before any project-creation flow","Treat empty-string org_id as missing in your config loader"],"tags":["validation","hosted-api","projects","sync"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}