mem0ai/mem0 · error · ValueError
Please provide both org_id and project_id
Error message
Please provide both org_id and project_id
What it means
When preparing query parameters, the project client accepts either both org_id and project_id or neither — supplying exactly one of them raises ValueError('Please provide both org_id and project_id'). This guard lives in _prepare_params() and runs before any HTTP request. It complements _validate_org_project by rejecting half-configured state.
Source
Thrown at mem0/client/project.py:106
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
if self.config.org_id and self.config.project_id:
kwargs["org_id"] = self.config.org_id
kwargs["project_id"] = self.config.project_id
elif self.config.org_id or self.config.project_id:
raise ValueError("Please provide both org_id and project_id")
return {k: v for k, v in kwargs.items() if v is not None}
def _prepare_org_params(self, kwargs: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
"""
Prepare query parameters for organization-level API requests.
Args:
kwargs: Additional keyword arguments.
Returns:
Dictionary containing prepared parameters.
Raises:
ValueError: If org_id is not provided.
"""
if kwargs is None:
kwargs = {}View on GitHub (pinned to 001c235229)
Solutions
- Set both org_id and project_id on the client (or clear both to run org/user-level calls)
- Check for half-configured env vars: one of MEM0_ORG_ID / MEM0_PROJECT_ID defined and the other missing
- Fail fast at startup with an explicit assert on the config before creating the client
Example fix
# before client = MemoryClient(api_key=API_KEY, org_id="my-org") client.project.get() # ValueError # after client = MemoryClient(api_key=API_KEY, org_id="my-org", project_id="p1") client.project.get()
Defensive patterns
Strategy: validation
Validate before calling
has_org = bool(cfg.org_id)
has_project = bool(cfg.project_id)
if has_org != has_project:
raise ConfigError("org_id and project_id must be set together or both omitted") Type guard
def params_pair_complete(cfg) -> bool:
return bool(cfg.org_id) == bool(cfg.project_id) Try / catch
try:
client.project.get()
except ValueError as e:
if "both org_id and project_id" in str(e):
fix_config_ids() # load both from secrets manager
raise Prevention
- Validate that the two IDs are either both present or both absent when loading config
- Use one env var prefix per scope and lint for half-defined pairs in CI
When it happens
Trigger: Calling any project method that builds params via _prepare_params() while the client config has org_id set but project_id missing (or vice versa). Also triggered if caller-supplied kwargs inject only one of the two keys.
Common situations: Setting MEM0_ORG_ID in CI but not MEM0_PROJECT_ID; instantiating the client from a partial config dict; refactors that drop one ID from a settings object while the other remains.
Related errors
- org_id and project_id must be set to access project operatio
- org_id must be set for organization-level operations
- org_id must be set to create a project
- At least one parameter must be provided for update: custom_i
- Mem0 API key is required
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/607e566d11210210.
Report an issue: GitHub.