{"record":{"id":"7fc3a7208e62fad2","repo":"Graphify-Labs/graphify","slug":"the-openai-package-is-required-for-this-backend","errorCode":null,"errorMessage":"the 'openai' package is required for this backend but is not installed. Install it with:  uv tool install \"graphifyy[openai]\" --force  (uv tool), or  pip install openai  (pip/venv install).","messagePattern":"the 'openai' package is required for this backend but is not installed\\. Install it with:  uv tool install \"graphifyy\\[openai\\]\" --force  \\(uv tool\\), or  pip install openai  \\(pip/venv install\\)\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"graphify/llm.py","lineNumber":2709,"sourceCode":"            \"messages\": [{\"role\": \"user\", \"content\": prompt}],\n            \"max_completion_tokens\": max_tokens,\n        }\n        azure_temp = _resolve_temperature(cfg.get(\"temperature\", 0), mdl)\n        if azure_temp is not None:\n            azure_kwargs[\"temperature\"] = azure_temp\n        resp = azure_client.chat.completions.create(**azure_kwargs)\n        if not resp.choices or resp.choices[0].message is None:\n            raise ValueError(\"Azure OpenAI returned empty or filtered response\")\n        au = getattr(resp, \"usage\", None)\n        if au is not None:\n            _rec(getattr(au, \"prompt_tokens\", 0), getattr(au, \"completion_tokens\", 0))\n        return resp.choices[0].message.content or \"\"\n\n    # OpenAI-compatible (kimi, openai, gemini, ollama)\n    try:\n        from openai import OpenAI\n    except ImportError as exc:\n        raise ImportError(_backend_pkg_hint(\"openai\", \"openai\")) from exc\n    client = OpenAI(api_key=key, base_url=cfg[\"base_url\"], timeout=_resolve_api_timeout(), max_retries=_resolve_max_retries())\n    kwargs: dict = {\n        \"model\": mdl,\n        \"messages\": [{\"role\": \"user\", \"content\": prompt}],\n        \"max_completion_tokens\": max_tokens,\n        # Force a single non-streamed response: some OpenAI-compatible gateways\n        # default to SSE streaming when `stream` is omitted, but the result here\n        # is always read as resp.choices[0]. Same fix as _call_openai_compat\n        # (#1223) — this path feeds the --dedup-llm tiebreaker.\n        \"stream\": False,\n    }\n    temperature = _resolve_temperature(cfg.get(\"temperature\", 0), mdl)\n    if temperature is not None:\n        kwargs[\"temperature\"] = temperature\n    if cfg.get(\"reasoning_effort\"):\n        kwargs[\"reasoning_effort\"] = cfg[\"reasoning_effort\"]\n    # Custom providers can override via providers.json `extra_body`; falls back\n    # to the moonshot default to preserve existing behavior.","sourceCodeStart":2691,"sourceCodeEnd":2727,"githubUrl":"https://github.com/Graphify-Labs/graphify/blob/7fe58b0b0f3873be9a21c30106b8b8527c353aa6/graphify/llm.py#L2691-L2727","documentation":"ImportError raised for every OpenAI-compatible backend (openai, gemini, kimi, ollama via /v1) when the 'openai' package is not installed. This is the fallback branch of the backend dispatch in llm.py:2706-2709 - anything not claude/claude-cli/bedrock/azure lands here, so the error also fires when a backend name is misspelled into the default path.","triggerScenarios":"`from openai import OpenAI` fails while handling backends openai/gemini/kimi/ollama (llm.py:2707-2709). Also triggered indirectly: an unknown backend string falls through the explicit branches and reaches this import, so a typo like 'openia' produces this same ImportError.","commonSituations":"Using the ollama backend (local, no API key) without realizing graphify drives it through the openai client library; typo'd backend names in providers.json silently falling through; base-package installs without the [openai] extra.","solutions":["Install the extra: `uv tool install \"graphifyy[openai]\" --force` or `pip install openai`.","Double-check the backend string for typos - an unrecognized name falls into this branch and misleadingly demands the openai package.","Verify with `python -c \"from openai import OpenAI\"` in the graphify interpreter."],"exampleFix":"# before\nbackend = \"openia\"   # typo -> falls through to OpenAI branch -> ImportError\n\n# after\nbackend = \"openai\"    # and ensure: pip install openai","handlingStrategy":"validation","validationCode":"import importlib.util\nif importlib.util.find_spec(\"openai\") is None:\n    raise SystemExit(\"OpenAI-compatible backends need the openai package: pip install openai\")","typeGuard":null,"tryCatchPattern":"try:\n    result = call_llm(prompt, backend=\"openai\")\nexcept ImportError as exc:\n    if \"openai\" in str(exc):\n        raise SystemExit(f\"Missing optional dep: {exc}\") from exc\n    raise","preventionTips":["Validate backend names against the documented list before dispatch so typos fail with a clear error.","Remember ollama still needs the openai package - 'local model' does not mean 'no SDK'.","Install all backend extras you might flip to; they are cheap."],"tags":["python","dependencies","openai","import-error","llm"],"backgroundTag":null,"analyzedSha":"7fe58b0b0f3873be9a21c30106b8b8527c353aa6","analyzedAt":"2026-08-14T19:23:21.323Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}