mem0ai/mem0 · error · ValueError
One of user_id, agent_id, run_id must be provided
Error message
One of user_id, agent_id, run_id must be provided
What it means
Mem0Proxy.completion()/the proxy's chat entry point requires exactly this: at least one of user_id, agent_id, or run_id so it knows which memory scope to read and write. Without a scope it cannot store or retrieve memories, so it refuses immediately with ValueError. All three parameters must not be simultaneously falsy.
Source
Thrown at mem0/proxy/main.py:98
tool_choice: Optional[Union[str, dict]] = None,
logprobs: Optional[bool] = None,
top_logprobs: Optional[int] = None,
parallel_tool_calls: Optional[bool] = None,
deployment_id=None,
extra_headers: Optional[dict] = None,
# soon to be deprecated params by OpenAI
functions: Optional[List] = None,
function_call: Optional[str] = None,
# set api_base, api_version, api_key
base_url: Optional[str] = None,
api_version: Optional[str] = None,
api_key: Optional[str] = None,
model_list: Optional[list] = None, # pass in a list of api_base,keys, etc.
):
if messages is None:
messages = []
if not any([user_id, agent_id, run_id]):
raise ValueError("One of user_id, agent_id, run_id must be provided")
if not litellm.supports_function_calling(model):
raise ValueError(
f"Model '{model}' does not support function calling. Please use a model that supports function calling."
)
prepared_messages = self._prepare_messages(messages)
if prepared_messages[-1]["role"] == "user":
self._async_add_to_memory(messages, user_id, agent_id, run_id, metadata, filters)
relevant_memories = self._fetch_relevant_memories(messages, user_id, agent_id, run_id, filters, top_k)
logger.debug(f"Retrieved {len(relevant_memories)} relevant memories")
prepared_messages[-1]["content"] = self._format_query_with_memories(messages, relevant_memories)
response = litellm.completion(
model=model,
messages=prepared_messages,
temperature=temperature,
top_p=top_p,View on GitHub (pinned to 001c235229)
Solutions
- Pass a scope explicitly: completion(messages=..., model=..., user_id='alice') (or agent_id/run_id for agent/session scoped memory)
- If wrapping the proxy, forward and validate user_id/agent_id/run_id before calling
- For per-user apps, derive user_id from your auth context and fail loudly upstream when it is missing
Example fix
# before resp = mem0_proxy.completion(messages=messages, model="gpt-4o-mini") # after resp = mem0_proxy.completion(messages=messages, model="gpt-4o-mini", user_id=user_id)
Defensive patterns
Strategy: validation
Validate before calling
if not any([user_id, agent_id, run_id]):
raise ValueError("user_id/agent_id/run_id required before calling proxy completion") Prevention
- Derive user_id from auth context and reject unauthenticated calls early
- Forward **kwargs carefully in wrappers; list scope args explicitly
- Add a unit test asserting scope args reach the proxy call
When it happens
Trigger: Calling mem0_proxy.completion(messages=..., model=...) without any of user_id/agent_id/run_id; passing them under wrong kwarg names (e.g. 'user' instead of 'user_id'); building a thin wrapper that forwards **kwargs but drops the scope arguments; per-user deployments where the caller assumed the proxy remembered the ID from init.
Common situations: Migrating code from direct litellm/openai calls (which need no user scope) to the Mem0 proxy and forgetting the new required arg; multi-user API gateways where the user_id is extracted from auth and is None for unauthenticated test requests.
Related errors
- LiteLLM failed: ${message}
- Model '{model}' does not support function calling. Please us
- Add requires at least one of User ID, Agent ID, Run ID, or A
- Provide text or metadata to update
- Mem0 memory event ${eventId} failed: ${reason}
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/d21565eb035224f2.
Report an issue: GitHub.