VectifyAI/PageIndex · error · PageIndexAPIError

api_key is an empty string. Pass a real PageIndex API key fo

Error message

api_key is an empty string. Pass a real PageIndex API key for cloud mode, or omit api_key entirely for local mode.

What it means

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.

Source

Thrown at pageindex/client.py:355

    def __init__(
        self,
        api_key: Optional[str] = None,
        *,
        index: Optional[Union[Mapping[str, Any], str]] = None,
        chat: Optional[Union[Mapping[str, Any], str]] = None,
        mode: Optional[str] = None,
        index_model: Optional[str] = None,
        chat_model: Optional[str] = None,
        model: Optional[str] = None,
        summary_model: Optional[str] = None,
        retrieve_model: Optional[str] = None,
        storage_path: Optional[Union[str, os.PathLike[str]]] = None,
        index_backend: Optional[dict[str, Any]] = None,
        chat_backend: Optional[dict[str, Any]] = None,
    ):
        if api_key == "":
            raise PageIndexAPIError(
                "api_key is an empty string. Pass a real PageIndex API key for "
                "cloud mode, or omit api_key entirely for local mode."
            )
        # Each side picks one spelling — its slot, or the flat arguments.
        # ``model`` sets every role, so it claims both sides.
        index_flat: dict[str, Any] = {
            name: value for name, value in
            (("api_key", api_key),
             ("index_model", index_model),
             ("summary_model", summary_model),
             ("index_backend", index_backend),
             ("storage_path", storage_path), ("model", model))
            if value is not None}
        chat_flat: dict[str, Any] = {
            name: value for name, value in
            (("chat_model", chat_model),
             ("retrieve_model", retrieve_model),
             ("chat_backend", chat_backend), ("model", model))

View on GitHub (pinned to afb5e11976)

Solutions

  1. Set a real PageIndex API key in the environment/export
  2. Use os.getenv("PAGEINDEX_API_KEY") (returns None when unset) instead of .get(..., "") so local mode is chosen by omission
  3. If local mode is intended, remove the api_key argument entirely

Example fix

# before
client = PageIndexClient(api_key=os.environ.get("PAGEINDEX_API_KEY", ""))
# after
client = PageIndexClient(api_key=os.environ.get("PAGEINDEX_API_KEY"))
Defensive patterns

Strategy: validation

Validate before calling

api_key = os.getenv("PAGEINDEX_API_KEY")
if api_key == "":
    api_key = None
client = PageIndexClient(api_key=api_key)

Type guard

def valid_api_key(k) -> bool:
    return k is None or (isinstance(k, str) and k != "")

Prevention

When it happens

Trigger: PageIndexClient(api_key=""), or api_key=os.getenv("PAGEINDEX_API_KEY") when the variable is set to empty or unset and defaults to "".

Common situations: CI environments where a secrets variable exists but is empty; shell scripts exporting API_KEY=; defensive .get(key, "") patterns.

Related errors


AI-assisted analysis of VectifyAI/PageIndex@afb5e11976 (2026-08-27). Data as JSON: /api/errors/aa45d8a7ce47be02. Report an issue: GitHub.