{"record":{"id":"aa45d8a7ce47be02","repo":"VectifyAI/PageIndex","slug":"api-key-is-an-empty-string-pass-a-real-pageindex","errorCode":null,"errorMessage":"api_key is an empty string. Pass a real PageIndex API key for cloud mode, or omit api_key entirely for local mode.","messagePattern":"api_key is an empty string\\. Pass a real PageIndex API key for cloud mode, or omit api_key entirely for local mode\\.","errorType":"validation","errorClass":"PageIndexAPIError","httpStatus":null,"severity":"error","filePath":"pageindex/client.py","lineNumber":355,"sourceCode":"\n    def __init__(\n        self,\n        api_key: Optional[str] = None,\n        *,\n        index: Optional[Union[Mapping[str, Any], str]] = None,\n        chat: Optional[Union[Mapping[str, Any], str]] = None,\n        mode: Optional[str] = None,\n        index_model: Optional[str] = None,\n        chat_model: Optional[str] = None,\n        model: Optional[str] = None,\n        summary_model: Optional[str] = None,\n        retrieve_model: Optional[str] = None,\n        storage_path: Optional[Union[str, os.PathLike[str]]] = None,\n        index_backend: Optional[dict[str, Any]] = None,\n        chat_backend: Optional[dict[str, Any]] = None,\n    ):\n        if api_key == \"\":\n            raise PageIndexAPIError(\n                \"api_key is an empty string. Pass a real PageIndex API key for \"\n                \"cloud mode, or omit api_key entirely for local mode.\"\n            )\n        # Each side picks one spelling — its slot, or the flat arguments.\n        # ``model`` sets every role, so it claims both sides.\n        index_flat: dict[str, Any] = {\n            name: value for name, value in\n            ((\"api_key\", api_key),\n             (\"index_model\", index_model),\n             (\"summary_model\", summary_model),\n             (\"index_backend\", index_backend),\n             (\"storage_path\", storage_path), (\"model\", model))\n            if value is not None}\n        chat_flat: dict[str, Any] = {\n            name: value for name, value in\n            ((\"chat_model\", chat_model),\n             (\"retrieve_model\", retrieve_model),\n             (\"chat_backend\", chat_backend), (\"model\", model))","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/VectifyAI/PageIndex/blob/afb5e119766630af6014b04fe8b53357527bc05e/pageindex/client.py#L337-L373","documentation":"api_key was passed as the empty string. An empty string is neither a valid cloud key nor the absence of a key (which selects local mode), so the SDK rejects it rather than silently doing the wrong thing.","triggerScenarios":"PageIndexClient(api_key=\"\"), or api_key=os.getenv(\"PAGEINDEX_API_KEY\") when the variable is set to empty or unset and defaults to \"\".","commonSituations":"CI environments where a secrets variable exists but is empty; shell scripts exporting API_KEY=; defensive .get(key, \"\") patterns.","solutions":["Set a real PageIndex API key in the environment/export","Use os.getenv(\"PAGEINDEX_API_KEY\") (returns None when unset) instead of .get(..., \"\") so local mode is chosen by omission","If local mode is intended, remove the api_key argument entirely"],"exampleFix":"# before\nclient = PageIndexClient(api_key=os.environ.get(\"PAGEINDEX_API_KEY\", \"\"))\n# after\nclient = PageIndexClient(api_key=os.environ.get(\"PAGEINDEX_API_KEY\"))","handlingStrategy":"validation","validationCode":"api_key = os.getenv(\"PAGEINDEX_API_KEY\")\nif api_key == \"\":\n    api_key = None\nclient = PageIndexClient(api_key=api_key)","typeGuard":"def valid_api_key(k) -> bool:\n    return k is None or (isinstance(k, str) and k != \"\")","tryCatchPattern":null,"preventionTips":["Use os.getenv() without a \"\" default so unset becomes None","Fail fast at startup with a clear message when a key variable exists but is empty"],"tags":["config","api-key","empty-argument","environment"],"backgroundTag":"empty-api-key","analyzedSha":"afb5e119766630af6014b04fe8b53357527bc05e","analyzedAt":"2026-08-27T11:20:48.519Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}