oobabooga/textgen · error · Exception

flask_cloudflared not installed. Make sure you installed the

Error message

flask_cloudflared not installed. Make sure you installed the requirements.txt for this extension.

What it means

Raised by _start_cloudflared (modules/api/utils.py:35) when starting with --public-api but the flask_cloudflared package is not importable. The tunnel cannot be created, so the exception aborts API startup for the public URL path.

Source

Thrown at modules/api/utils.py:35

    # Encode bytes into base64
    encoded_bytes = base64.b64encode(bytes_array)

    # Turn raw base64 encoded bytes into ASCII
    ascii_string = encoded_bytes.decode('ascii')
    return ascii_string


def debug_msg(*args, **kwargs):
    if int(os.environ.get("OPENEDAI_DEBUG", 0)):
        print(*args, **kwargs)


def _start_cloudflared(port: int, tunnel_id: str, max_attempts: int = 3, on_start: Optional[Callable[[str], None]] = None):
    try:
        from flask_cloudflared import _run_cloudflared
    except ImportError:
        print('You should install flask_cloudflared manually')
        raise Exception(
            'flask_cloudflared not installed. Make sure you installed the requirements.txt for this extension.')

    for _ in range(max_attempts):
        try:
            if tunnel_id is not None:
                public_url = _run_cloudflared(port, port + 1, tunnel_id=tunnel_id)
            else:
                public_url = _run_cloudflared(port, port + 1)

            if on_start:
                on_start(public_url)

            return
        except Exception:
            traceback.print_exc()
            time.sleep(3)

    raise Exception('Could not start cloudflared.')

View on GitHub (pinned to ed888c71f2)

Solutions

  1. pip install flask-cloudflared (project name uses a hyphen) into the same environment running server.py.
  2. If it still fails, verify with: python -c 'from flask_cloudflared import _run_cloudflared'.
  3. Long term, drop --public-api and expose the API over LAN (--listen) behind your own reverse proxy/tunnel.

Example fix

# before
python server.py --api --public-api
# Exception: flask_cloudflared not installed...

# after
pip install flask-cloudflared
python server.py --api --public-api
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util

if importlib.util.find_spec('flask_cloudflared') is None and USE_PUBLIC_API:
    raise SystemExit('pip install flask-cloudflared before using --public-api')

Prevention

When it happens

Trigger: Launching with --api --public-api in an environment where 'from flask_cloudflared import _run_cloudflared' raises ImportError (package absent, or present but broken/incompatible Python).

Common situations: Installed only requirements.txt for the main app but not the extension/API extras; using a manually built venv that skipped optional deps; renamed/removed package in newer requirement sets; wrong venv activated.

Related errors


AI-assisted analysis of oobabooga/textgen@ed888c71f2 (2026-08-15). Data as JSON: /api/errors/947dca6bf3be9a49. Report an issue: GitHub.