mem0ai/mem0 · error · ValueError

Either a client or URL and token must be provided.

Error message

Either a client or URL and token must be provided.

What it means

UpstashVectorConfig requires either an existing 'client' (an upstash_vector.Index instance) or both a URL and a token. The validator resolves url/token from the config first, then falls back to UPSTASH_VECTOR_REST_URL and UPSTASH_VECTOR_REST_TOKEN env vars; if after that fallback either value (or both) is missing and no client was given, it raises. It also writes the env-resolved values back into the config so construction succeeds later.

Source

Thrown at mem0/configs/vector_stores/upstash_vector.py:31

    Index: ClassVar[type] = Index

    url: Optional[str] = Field(None, description="URL for Upstash Vector index")
    token: Optional[str] = Field(None, description="Token for Upstash Vector index")
    client: Optional[Index] = Field(None, description="Existing `upstash_vector.Index` client instance")
    collection_name: str = Field("mem0", description="Namespace to use for the index")
    enable_embeddings: bool = Field(
        False, description="Whether to use built-in upstash embeddings or not. Default is True."
    )

    @model_validator(mode="before")
    @classmethod
    def check_credentials_or_client(cls, values: Dict[str, Any]) -> Dict[str, Any]:
        client = values.get("client")
        url = values.get("url") or os.environ.get("UPSTASH_VECTOR_REST_URL")
        token = values.get("token") or os.environ.get("UPSTASH_VECTOR_REST_TOKEN")

        if not client and not (url and token):
            raise ValueError("Either a client or URL and token must be provided.")

        # Persist the env-resolved credentials so the provider constructor receives
        # them; the validator used to check the env vars but drop them, so an
        # env-var-only config passed validation and then raised on build.
        if not client:
            values["url"] = url
            values["token"] = token
        return values

    model_config = ConfigDict(arbitrary_types_allowed=True)

View on GitHub (pinned to 001c235229)

Solutions

  1. Set both UPSTASH_VECTOR_REST_URL and UPSTASH_VECTOR_REST_TOKEN, or pass both url= and token= in the config
  2. Or inject a pre-built client: config={'client': Index(url=..., token=...)}
  3. If using .env, ensure it is loaded (python-dotenv) before instantiating Memory

Example fix

# before
config = {"url": "https://my-index.upstash.io"}  # token missing

# after
config = {"url": "https://my-index.upstash.io", "token": "UPSTASH_TOKEN"}
Defensive patterns

Strategy: validation

Validate before calling

import os
url = cfg.get("url") or os.environ.get("UPSTASH_VECTOR_REST_URL")
token = cfg.get("token") or os.environ.get("UPSTASH_VECTOR_REST_TOKEN")
if not cfg.get("client") and not (url and token):
    raise ConfigError("Upstash needs a client, or both url and token (values or env vars)")

Prevention

When it happens

Trigger: Passing url but not token (or vice versa); setting only one of the two env vars; passing client=None explicitly with no url/token; env vars set under different names (e.g. UPSTASH_VECTOR_URL).

Common situations: Copying only UPSTASH_VECTOR_REST_URL from the Upstash dashboard and forgetting the token; .env file not loaded before Memory(...) is constructed; assuming the REST URL alone is enough because the console shows it first.

Related errors


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