{"record":{"id":"ad0386cd6e8e068d","repo":"Graphify-Labs/graphify","slug":"the-pkg-package-is-required-for-this-backend-b","errorCode":null,"errorMessage":"the '{pkg}' package is required for this backend but is not installed. Install it with:  uv tool install \"graphifyy[{extra}]\" --force  (uv tool), or  pip install {pkg}  (pip/venv install).","messagePattern":"the '(.+?)' package is required for this backend but is not installed\\. Install it with:  uv tool install \"graphifyy\\[(.+?)\\]\" --force  \\(uv tool\\), or  pip install (.+?)  \\(pip/venv install\\)\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"graphify/llm.py","lineNumber":1184,"sourceCode":"    base_url: str,\n    api_key: str,\n    model: str,\n    user_message: str,\n    temperature: float | None = 0,\n    reasoning_effort: str | None = None,\n    max_completion_tokens: int = 8192,\n    *,\n    backend: str = \"\",\n    deep_mode: bool = False,\n    images: list[_ImageRef] | None = None,\n    extra_body: dict | None = None,\n) -> dict:\n    \"\"\"Call any OpenAI-compatible API (Kimi, OpenAI, etc.) and return parsed JSON.\"\"\"\n    try:\n        from openai import OpenAI\n    except ImportError as exc:\n        extra = backend if backend in (\"kimi\", \"gemini\", \"openai\", \"ollama\") else \"openai\"\n        raise ImportError(_backend_pkg_hint(\"openai\", extra)) from exc\n\n    # Local backends (ollama, llama.cpp, vLLM) routinely take >60s for a\n    # single chunk on a large model — far longer than the openai SDK's\n    # default. Honour GRAPHIFY_API_TIMEOUT (seconds) for explicit override;\n    # default to 600s, which is long enough for a 31B model on a 16k chunk\n    # but still bounds runaway connections (issue #792 addendum).\n    # The SDK's transient-error retries (default 6) exist for cloud rate limits\n    # (429). A local Ollama server does not rate-limit, and if it wedges it will\n    # not recover by retrying, so 6 retries turn a 180s --api-timeout into a\n    # ~21min block (7 attempts x 180s) with no progress (#1686). Default ollama\n    # to 0 SDK retries so --api-timeout is the hard wall-clock bound and a hung\n    # request fails fast into the chunk-level retry/skip. An explicit\n    # GRAPHIFY_MAX_RETRIES still wins for users who want it.\n    _retries = _resolve_max_retries()\n    if backend == \"ollama\" and not os.environ.get(\"GRAPHIFY_MAX_RETRIES\", \"\").strip():\n        _retries = 0\n    client = OpenAI(api_key=api_key, base_url=base_url, timeout=_resolve_api_timeout(),\n                    max_retries=_retries)","sourceCodeStart":1166,"sourceCodeEnd":1202,"githubUrl":"https://github.com/Graphify-Labs/graphify/blob/7fe58b0b0f3873be9a21c30106b8b8527c353aa6/graphify/llm.py#L1166-L1202","documentation":"Raised when the OpenAI-compatible call path (`_call_openai_compat`) cannot import the `openai` SDK. graphify routes many backends (openai, kimi, gemini-via-openai, ollama, deepseek, moonshot) through the `openai` Python package, so a missing package aborts the call before any request is made. The message is generated by `_backend_pkg_hint(\"openai\", extra)` and includes the correct uv/pip install command for the selected backend.","triggerScenarios":"Calling `extract_files_direct(..., backend=\"kimi\"|\"openai\"|\"ollama\"|...)` (or letting `detect_backend()` pick one) when `import openai` fails — i.e. graphify was installed without the `openai` extra and no openai SDK exists in the environment.","commonSituations":"Installing graphify via `pip install graphifyy` (no extras) and then selecting a cloud/local backend that rides the OpenAI compat layer; using `uv tool install graphifyy` without `[openai]` or `[kimi]` etc.; a venv where openai was uninstalled or pinned-away by another dependency conflict.","solutions":["Install the matching extra: `uv tool install \"graphifyy[openai]\" --force` (or the backend-specific extra shown in the message, e.g. `[kimi]`), or `pip install openai` inside the active venv.","Verify with `python -c \"import openai\"` in the exact interpreter/venv graphify runs under.","If installed as a uv tool, remember tools live in an isolated venv — install the extra there, not in your project venv."],"exampleFix":"# before\nuv tool install graphifyy --force\n\n# after\nuv tool install \"graphifyy[openai]\" --force   # or [kimi], [gemini], ... for that backend","handlingStrategy":"validation","validationCode":"import importlib.util\nfrom graphify.llm import BACKENDS\n\ndef can_use_openai_compat(backend: str) -> bool:\n    return importlib.util.find_spec(\"openai\") is not None and backend in BACKENDS\n\n# before extraction:\nif not can_use_openai_compat(\"kimi\"):\n    raise SystemExit(\"install graphifyy[openai] (or the backend extra) first\")","typeGuard":null,"tryCatchPattern":"try:\n    extract_files_direct(files, root, backend=\"kimi\")\nexcept ImportError as e:\n    if \"openai\" in str(e):\n        subprocess.run([sys.executable, \"-m\", \"pip\", \"install\", \"openai\"], check=True)\n    else:\n        raise","preventionTips":["Install the backend extra at setup time: `pip install \"graphifyy[openai,kimi,anthropic,bedrock]\"` for every backend you plan to use.","For uv tool installs, remember extras go on the tool, not your project venv.","Add a startup check `importlib.util.find_spec(\"openai\")` in pipelines that select OpenAI-compat backends."],"tags":["dependency","import-error","installation","openai","backend"],"backgroundTag":null,"analyzedSha":"7fe58b0b0f3873be9a21c30106b8b8527c353aa6","analyzedAt":"2026-08-14T19:23:21.323Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}