Graphify-Labs/graphify · error · ValueError

No API key for backend '{backend}'. Set {_format_backend_env

Error message

No API key for backend '{backend}'. Set {_format_backend_env_keys(backend)} or pass api_key=.

What it means

Raised by `extract_files_direct` after backend resolution when no API key is available: neither the `api_key=` parameter nor `_get_backend_api_key(backend)` (env-var lookup) produced a value. `bedrock` (AWS credential chain) and `claude-cli` (CLI's own auth) are exempt; `ollama` gets a placeholder key with a warning instead (F-029). Every other backend needs an explicit key.

Source

Thrown at graphify/llm.py:1786

        raise ValueError(f"Unknown backend {backend!r}. Available: {sorted(BACKENDS)}")

    cfg = BACKENDS[backend]
    key = api_key or _get_backend_api_key(backend)
    if not key and backend == "ollama":
        # Ollama ignores auth but the OpenAI client library requires a non-empty
        # string. Use a placeholder and surface a visible warning so this never
        # silently routes traffic without the user realising — see F-029.
        ollama_url = _resolve_ollama_base_url(cfg.get("base_url", ""))
        _validate_ollama_base_url(ollama_url)
        print(
            "[graphify] WARNING: ollama backend selected with no OLLAMA_API_KEY set; "
            f"sending corpus to {ollama_url}. Set OLLAMA_API_KEY (any non-empty value) "
            "to suppress this warning.",
            file=sys.stderr,
        )
        key = "ollama"
    if not key and backend not in ("bedrock", "claude-cli"):
        raise ValueError(
            f"No API key for backend '{backend}'. "
            f"Set {_format_backend_env_keys(backend)} or pass api_key=."
        )
    mdl = model or _default_model_for_backend(backend)
    # Separate raster images from text-like files. Text goes through _read_files
    # as before; images become structured refs the backend renders as pixels
    # (vision backends) or as a text reference node (everything else).
    text_files, image_files = _partition_semantic_files(files)
    user_msg = _read_files(text_files, root)
    vision = _backend_supports_vision(backend)
    # Only base64 (inline) vision backends need the bytes loaded + size-capped;
    # path-based backends (claude-cli) and non-vision backends do not.
    read_bytes = vision and backend not in _PATH_IMAGE_BACKENDS
    image_refs = _build_image_refs(image_files, root, read_bytes=read_bytes) if image_files else []
    if image_refs and not vision:
        image_refs = _strip_pixels(image_refs)
    max_out = _resolve_max_tokens(cfg.get("max_tokens", 8192))

View on GitHub (pinned to 7fe58b0b0f)

Solutions

  1. Set the env var named by `_format_backend_env_keys(backend)` (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY, AZURE_OPENAI_API_KEY) in the process running graphify.
  2. Or pass `api_key=` directly to `extract_files_direct`.
  3. Verify the variable name matches the backend you selected — a Gemini key won't satisfy the openai backend.
  4. For Ollama the warning (not error) path applies; set OLLAMA_API_KEY to any non-empty value to silence it.

Example fix

# before
extract_files_direct(files, root, backend="openai")  # OPENAI_API_KEY unset

# after
extract_files_direct(files, root, backend="openai", api_key=os.environ["OPENAI_API_KEY"])
Defensive patterns

Strategy: validation

Validate before calling

from graphify.llm import _get_backend_api_key, BACKENDS

def backend_has_credentials(name: str) -> bool:
    if name in ("bedrock", "claude-cli"):
        return True
    if name == "ollama":
        return True  # placeholder key path
    return bool(_get_backend_api_key(name))

if not backend_has_credentials("openai"):
    raise SystemExit("export OPENAI_API_KEY or pass api_key=")

Prevention

When it happens

Trigger: Selecting a key-based backend (gemini, openai, kimi, deepseek, moonshot, claude, azure) with its env var unset and no `api_key=` passed — e.g. AZURE_OPENAI_API_KEY missing while AZURE_OPENAI_ENDPOINT is set.

Common situations: Env var present in the login shell but not in the tool's process (IDE, cron, docker); key set for one provider but `backend=` names another; expired/rotated key deleted from the environment; `.env` not loaded.

Related errors


AI-assisted analysis of Graphify-Labs/graphify@7fe58b0b0f (2026-08-14). Data as JSON: /api/errors/7076db270a7ccc4f. Report an issue: GitHub.