unclecode/crawl4ai · error · ValueError

[NSTProxy] token and channel_id are required

Error message

[NSTProxy] token and channel_id are required

What it means

Raised by BrowserConfig (NSTProxy helper) when set_nstproxy() is called without a token or channel_id. NSTProxy is a paid residential-proxy service; both credentials are mandatory to call its generate-apiproxies API. The library validates them up front, before any network call.

Source

Thrown at crawl4ai/async_configs.py:1062

        Get your NSTProxy token from: https://app.nstproxy.com/profile

        Args:
            token (str): NSTProxy API token.
            channel_id (str): NSTProxy channel ID.
            country (str, optional): Country code (default: "ANY").
            state (str, optional): State code (default: "").
            city (str, optional): City name (default: "").
            protocol (str, optional): Proxy protocol ("http" or "socks5"). Defaults to "http".
            session_duration (int, optional): Session duration in minutes (0 = rotate each request). Defaults to 10.

        Raises:
            ValueError: If the API response format is invalid.
            PermissionError: If the API returns an error message.
        """

        # --- Validate input early ---
        if not token or not channel_id:
            raise ValueError("[NSTProxy] token and channel_id are required")

        if protocol not in ("http", "socks5"):
            raise ValueError(f"[NSTProxy] Invalid protocol: {protocol}")

        # --- Build NSTProxy API URL ---
        params = {
            "fType": 2,
            "count": 1,
            "channelId": channel_id,
            "country": country,
            "protocol": protocol,
            "sessionDuration": session_duration,
            "token": token,
        }
        if state:
            params["state"] = state
        if city:
            params["city"] = city

View on GitHub (pinned to 7e80152142)

Solutions

  1. Pass both required credentials: set_nstproxy(token=os.environ['NSTPROXY_TOKEN'], channel_id='your-channel')
  2. If using env vars, verify they are set and non-empty before calling (print bool(os.getenv(...)))
  3. Confirm your NSTProxy dashboard shows a valid channel id — channel_id comes from NSTProxy, not your account password

Example fix

// before
cfg.set_nstproxy(channel_id="12345")  # token missing
// after
import os
cfg.set_nstproxy(token=os.environ["NSTPROXY_TOKEN"], channel_id="12345")
Defensive patterns

Strategy: validation

Validate before calling

import os

def nstproxy_ready():
    return bool(os.getenv("NSTPROXY_TOKEN")) and bool(os.getenv("NSTPROXY_CHANNEL_ID"))

# before config:
assert nstproxy_ready(), "NSTPROXY_TOKEN / NSTPROXY_CHANNEL_ID missing"

Try / catch

try:
    cfg.set_nstproxy(token=t, channel_id=c)
except ValueError as e:
    if "token and channel_id" in str(e):
        raise RuntimeError(f"Missing NSTProxy credentials: {e}") from e
    raise

Prevention

When it happens

Trigger: Calling config.set_nstproxy(channel_id="...") with no token, or set_nstproxy(token="...") with no/empty channel_id, or passing empty strings for either (the check is falsy: `if not token or not channel_id`).

Common situations: Loading NSTProxy credentials from environment variables that are unset in CI or a deploy environment; typos in kwarg names (e.g. channelid); copy-pasting example code that placeholders the token.

Related errors


AI-assisted analysis of unclecode/crawl4ai@7e80152142 (2026-08-14). Data as JSON: /api/errors/73dedd7f0e21fae1. Report an issue: GitHub.