mem0ai/mem0 · error · ValueError
Pinecone API key must be provided either as a parameter or a
Error message
Pinecone API key must be provided either as a parameter or as an environment variable
What it means
Raised in Pinecone.__init__ when neither an `api_key` constructor parameter nor a PINECONE_API_KEY environment variable is available. mem0 deliberately fails fast instead of constructing a client that would 401 on first use. Note the `client` short-circuit: passing a pre-built Pinecone client skips the check entirely.
Source
Thrown at mem0/vector_stores/pinecone.py:63
collection_name (str): Name of the index/collection.
embedding_model_dims (int): Dimensions of the embedding model.
client (Pinecone, optional): Existing Pinecone client instance. Defaults to None.
api_key (str, optional): API key for Pinecone. Defaults to None.
environment (str, optional): Pinecone environment. Defaults to None.
serverless_config (Dict, optional): Configuration for serverless deployment. Defaults to None.
pod_config (Dict, optional): Configuration for pod-based deployment. Defaults to None.
hybrid_search (bool, optional): Whether to enable hybrid search. Defaults to False.
metric (str, optional): Distance metric for vector similarity. Defaults to "cosine".
batch_size (int, optional): Batch size for operations. Defaults to 100.
extra_params (Dict, optional): Additional parameters for Pinecone client. Defaults to None.
namespace (str, optional): Namespace for the collection. Defaults to None.
"""
if client:
self.client = client
else:
api_key = api_key or os.environ.get("PINECONE_API_KEY")
if not api_key:
raise ValueError(
"Pinecone API key must be provided either as a parameter or as an environment variable"
)
params = extra_params or {}
self.client = Pinecone(api_key=api_key, **params)
self.collection_name = collection_name
self.embedding_model_dims = embedding_model_dims
self.environment = environment
self.serverless_config = serverless_config
self.pod_config = pod_config
self.hybrid_search = hybrid_search
self.metric = metric
self.batch_size = batch_size
self.namespace = namespace
self.sparse_encoder = None
if self.hybrid_search:View on GitHub (pinned to 001c235229)
Solutions
- Export the variable in the process that runs mem0: `export PINECONE_API_KEY=...` or load it via python-dotenv before constructing Memory.
- Or pass it explicitly in config: `vector_store={"provider": "pinecone", "config": {"api_key": os.environ["PINECONE_API_KEY"], ...}}`.
- Or inject a pre-built client (`client=Pinecone(api_key=...)`) which bypasses the key lookup — useful when the key lives in a secrets manager.
Example fix
# before
memory = Memory.from_config({"vector_store": {"provider": "pinecone", "config": {"collection_name": "mem"}}})
# ValueError: Pinecone API key must be provided...
# after
import os
from dotenv import load_dotenv
load_dotenv()
memory = Memory.from_config({
"vector_store": {
"provider": "pinecone",
"config": {"collection_name": "mem", "embedding_model_dims": 1536},
}
}) # picks up PINECONE_API_KEY from env Defensive patterns
Strategy: validation
Validate before calling
import os
def pinecone_ready() -> bool:
return bool(os.environ.get("PINECONE_API_KEY"))
if not pinecone_ready():
raise SystemExit("PINECONE_API_KEY not set; refusing to start with pinecone provider") Try / catch
try:
store = Pinecone(collection_name="mem", embedding_model_dims=1536)
except ValueError as e:
if "API key" in str(e):
raise RuntimeError("Pinecone credentials missing; check PINECONE_API_KEY in the runtime env") from e
raise Prevention
- Load .env files (python-dotenv) as the first statement of the entrypoint, before any Memory construction.
- Fail fast at boot on required secrets rather than at first query.
- Prefer passing an explicit api_key (or pre-built client) from your secrets manager instead of relying on ambient env.
When it happens
Trigger: `Pinecone(collection_name=..., embedding_model_dims=...)` with api_key=None and no PINECONE_API_KEY in os.environ; or building Memory with vector_store config `"provider": "pinecone"` while the key exists only in a .env file that was never loaded into the process env.
Common situations: Forgetting python-dotenv/load_dotenv() before creating Memory; running the same code in CI where secrets are injected under a different variable name; shell exports not visible to a systemd service or Docker container; key set only in the deployment platform's UI but not passed to the container.
Related errors
- Turbopuffer API key must be provided either as a parameter o
- Pinecone API key required: pass apiKey or set PINECONE_API_K
- Mem0 API key is required
- Mem0 API key cannot be empty
- organizationId and projectId must be set to access instructi
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/64064faa4418c1df.
Report an issue: GitHub.