{"record":{"id":"ff8f30b79f46fba0","repo":"VectifyAI/PageIndex","slug":"messages-drives-your-own-chat-model-and-requires-t","errorCode":null,"errorMessage":"messages drives your own chat model and requires the Anthropic SDK — pip install anthropic (or pip install 'pageindex[anthropic]').","messagePattern":"messages drives your own chat model and requires the Anthropic SDK — pip install anthropic \\(or pip install 'pageindex\\[anthropic\\]'\\)\\.","errorType":"exception","errorClass":"PageIndexAPIError","httpStatus":null,"severity":"error","filePath":"pageindex/local_chat.py","lineNumber":871,"sourceCode":"        transcript = streamed.to_input_list()[len(items):]\n        sequence += 1\n        status = recorded.get(\"status\") or \"completed\"\n        terminal = {\"incomplete\": \"response.incomplete\",\n                    \"failed\": \"response.failed\"}.get(status,\n                                                     \"response.completed\")\n        yield {\"type\": terminal, \"sequence_number\": sequence,\n               \"response\": envelope(transcript, streamed.raw_responses)}\n\n    return _stream_sync(agen)\n\n\n# ── Anthropic engine (messages) ──\n\ndef _require_anthropic() -> None:\n    try:\n        import anthropic  # noqa: F401\n    except ImportError as exc:\n        raise PageIndexAPIError(\n            \"messages drives your own chat model and requires the \"\n            \"Anthropic SDK — \"\n            \"pip install anthropic (or pip install 'pageindex[anthropic]').\"\n        ) from exc\n    try:\n        from anthropic import beta_tool  # noqa: F401\n        from anthropic.lib.tools import ToolError  # noqa: F401\n    except ImportError as exc:\n        raise PageIndexAPIError(\n            \"messages requires anthropic >= 0.108.0 (the tool \"\n            \"runner with ToolError) — pip install -U anthropic.\"\n        ) from exc\n\n\n_ANTHROPIC_CLIENTS: dict = {}  # backend key -> client, kept open for reuse\n\n\ndef _anthropic_client(backend=None):","sourceCodeStart":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/VectifyAI/PageIndex/blob/afb5e119766630af6014b04fe8b53357527bc05e/pageindex/local_chat.py#L853-L889","documentation":"The messages() API runs on your own Anthropic chat model, so pageindex needs the Anthropic Python SDK at runtime. _require_anthropic() probes for the anthropic package before starting the tool runner and raises PageIndexAPIError when the import fails. This is purely an environment/dependency issue, not a request problem.","triggerScenarios":"Calling client.messages(...) (which delegates to run_messages) in an environment where `import anthropic` raises ImportError — e.g. pageindex installed without the [anthropic] extra, or a fresh venv/CI image that never installed the SDK.","commonSituations":"Installing pageindex via `pip install pageindex` (without the [anthropic] extra) and then calling the messages door; deploying to a slim Docker image or CI runner that strips optional dependencies; a different library shadowing the anthropic module name.","solutions":["pip install anthropic (or pip install 'pageindex[anthropic]' to get the pinned extra)","Verify the import works in the target environment: python -c \"import anthropic\"","If deploying, add anthropic to your requirements.txt/lockfile alongside pageindex"],"exampleFix":"# before\nresp = client.messages(\"summarize this doc\")  # PageIndexAPIError\n# after\n# pip install 'pageindex[anthropic]'\nresp = client.messages(\"summarize this doc\")","handlingStrategy":"validation","validationCode":"try:\n    import anthropic  # noqa\nexcept ImportError:\n    raise SystemExit(\"Install first: pip install 'pageindex[anthropic]'\")","typeGuard":null,"tryCatchPattern":"try:\n    resp = client.messages(\"hi\")\nexcept PageIndexAPIError as e:\n    if \"requires the Anthropic SDK\" in str(e):\n        subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", \"anthropic\"])\n        resp = client.messages(\"hi\")\n    else:\n        raise","preventionTips":["Install the [anthropic] extra in the same command as pageindex","Add anthropic to your lockfile/requirements","Smoke-test `import anthropic` in your Dockerfile build stage"],"tags":["anthropic","dependency","install","sdk"],"backgroundTag":"missing-optional-dependency","analyzedSha":"afb5e119766630af6014b04fe8b53357527bc05e","analyzedAt":"2026-08-27T11:20:48.519Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}