{"record":{"id":"4fcc9df1dae22fd1","repo":"mem0ai/mem0","slug":"turbopuffer-api-key-must-be-provided-either-as-a-p","errorCode":null,"errorMessage":"Turbopuffer API key must be provided either as a parameter or via TURBOPUFFER_API_KEY environment variable","messagePattern":"Turbopuffer API key must be provided either as a parameter or via TURBOPUFFER_API_KEY environment variable","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/turbopuffer.py","lineNumber":51,"sourceCode":"        batch_size: int = 100,\n        extra_params: Optional[Dict[str, Any]] = None,\n    ):\n        \"\"\"\n        Initialize the Turbopuffer vector store.\n\n        Args:\n            collection_name (str): Name of the namespace/collection.\n            embedding_model_dims (int): Dimensions of the embedding model.\n            api_key (str, optional): API key for Turbopuffer. Defaults to None.\n            region (str, optional): Turbopuffer region. Defaults to \"gcp-us-central1\".\n            distance_metric (str, optional): Distance metric for vector similarity.\n                Options: \"cosine_distance\" or \"euclidean_squared\". Defaults to \"cosine_distance\".\n            batch_size (int, optional): Batch size for operations. Defaults to 100.\n            extra_params (Dict, optional): Additional parameters for Turbopuffer client. Defaults to None.\n        \"\"\"\n        api_key = api_key or os.environ.get(\"TURBOPUFFER_API_KEY\")\n        if not api_key:\n            raise ValueError(\n                \"Turbopuffer API key must be provided either as a parameter or via TURBOPUFFER_API_KEY environment variable\"\n            )\n\n        params = extra_params or {}\n        params[\"region\"] = region\n\n        self.client = TurbopufferClient(api_key=api_key, **params)\n        self.collection_name = collection_name\n        self.embedding_model_dims = embedding_model_dims\n        self.distance_metric = distance_metric\n        self.batch_size = batch_size\n\n        self.namespace = self.client.namespace(self.collection_name)\n\n    def create_col(self, name=None, vector_size=None, distance=None):\n        \"\"\"\n        Create a new namespace in Turbopuffer.\n        Namespaces are created implicitly on first upsert, so this is a no-op.","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/turbopuffer.py#L33-L69","documentation":"Raised in Turbopuffer.__init__ when neither an api_key parameter nor the TURBOPUFFER_API_KEY environment variable is present. Unlike some providers, this store has no client-injection escape hatch — a key is always required because every Turbopuffer namespace operation is authenticated.","triggerScenarios":"Constructing Turbopuffer or Memory with provider \"turbopuffer\" while api_key is None and TURBOPUFFER_API_KEY is unset — e.g. the key lives in a .env file never loaded, or was added under a differently named variable in CI secrets.","commonSituations":"Forgetting load_dotenv() before building Memory; secret managers exporting TURBOPUFFER_KEY instead of TURBOPUFFER_API_KEY; local works but container/scheduled job fails because the env var was only set in the interactive shell.","solutions":["Set the env var in the running process: `export TURBOPUFFER_API_KEY=...` or load .env with python-dotenv before init.","Or pass it explicitly: `\"config\": {\"api_key\": os.environ[\"TURBOPUFFER_API_KEY\"], ...}`.","For cloud deploys, add TURBOPUFFER_API_KEY to the service's environment/secret configuration, not just the build environment."],"exampleFix":"# before\nmemory = Memory.from_config({\n    \"vector_store\": {\"provider\": \"turbopuffer\", \"config\": {\"collection_name\": \"mem\"}}\n})  # ValueError\n\n# after\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\nmemory = Memory.from_config({\n    \"vector_store\": {\n        \"provider\": \"turbopuffer\",\n        \"config\": {\"collection_name\": \"mem\", \"embedding_model_dims\": 1536},\n    }\n})","handlingStrategy":"validation","validationCode":"import os\n\ndef turbopuffer_ready() -> bool:\n    return bool(os.environ.get(\"TURBOPUFFER_API_KEY\"))\n\nif not turbopuffer_ready():\n    raise SystemExit(\"TURBOPUFFER_API_KEY not set; cannot start with turbopuffer provider\")","typeGuard":null,"tryCatchPattern":"try:\n    store = Turbopuffer(collection_name=\"mem\", embedding_model_dims=1536)\nexcept ValueError as e:\n    if \"API key\" in str(e):\n        raise RuntimeError(\"Turbopuffer credentials missing; set TURBOPUFFER_API_KEY\") from e\n    raise","preventionTips":["Note this provider has no client-injection fallback — a key is mandatory, so check it at boot.","Wire the secret from your secrets manager into env or explicit config; never assume ambient env in containers.","Add a config preflight that fails deployment, not the first request, when the key is absent."],"tags":["configuration","turbopuffer","api-key","environment-variables","vector-store"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}