HKUDS/DeepTutor · warning · MinerUError

No API token configured.

Error message

No API token configured.

What it means

The Settings → MinerU 'Test' button (verify_credentials) refuses to run when config.api_keys is empty.

Source

Thrown at deeptutor/services/parsing/engines/mineru/cloud.py:215

            if state == _TERMINAL_FAIL:
                err = str(entry.get("err_msg") or "unknown error")
                raise MinerUError(f"MinerU failed to parse the document: {err}")
        if time.monotonic() >= deadline:
            raise MinerUError(
                f"MinerU parsing timed out after {int(timeout)}s "
                f"(last state: {last_state or 'unknown'})."
            )
        time.sleep(poll_interval)


def verify_credentials(config: MinerUConfig) -> None:
    """Best-effort connectivity / token check for the Settings → MinerU "Test"
    button. Requests an upload slot (which does not consume parsing quota and
    is never followed by an upload, so it simply expires) and validates the
    business code. Raises :class:`MinerUError` with a user-facing message on
    any failure."""
    if not config.api_keys:
        raise MinerUError("No API token configured.")
    base_url = config.api_base_url.rstrip("/")
    key_pool = KeyPool(config.api_keys)
    body: dict[str, object] = {
        "files": [{"name": "connectivity-check.pdf", "is_ocr": False}],
        "model_version": config.model_version,
        "enable_formula": config.enable_formula,
        "enable_table": config.enable_table,
    }
    if config.api_language:
        body["language"] = config.api_language
    with httpx.Client(base_url=base_url, headers={"Accept": "application/json"}) as client:
        _post_json(client, "/api/v4/file-urls/batch", body, key_pool)


def _download(zip_url: str) -> bytes:
    try:
        response = httpx.get(zip_url, timeout=_DOWNLOAD_TIMEOUT_SECONDS, follow_redirects=True)
        response.raise_for_status()

View on GitHub (pinned to 3e82f13042)

Solutions

  1. Enter an API token in Settings → MinerU, then Test again.
  2. Verify the settings JSON (data/user/settings) actually persisted the key.
Defensive patterns

Strategy: validation

Validate before calling

if not cfg.api_keys:
    return "Add a token in Settings → MinerU before testing."

Try / catch

try:
    verify_credentials(cfg)
except MinerUError as e:
    show_settings_error(str(e))

Prevention

When it happens

Trigger: Clicking Test with cloud mode configured but no token saved.

Common situations: User selects cloud mode before entering a token, or settings file failed to save.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/bfce896af2797362. Report an issue: GitHub.