{"record":{"id":"73dedd7f0e21fae1","repo":"unclecode/crawl4ai","slug":"nstproxy-token-and-channel-id-are-required","errorCode":null,"errorMessage":"[NSTProxy] token and channel_id are required","messagePattern":"\\[NSTProxy\\] token and channel_id are required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crawl4ai/async_configs.py","lineNumber":1062,"sourceCode":"        Get your NSTProxy token from: https://app.nstproxy.com/profile\n\n        Args:\n            token (str): NSTProxy API token.\n            channel_id (str): NSTProxy channel ID.\n            country (str, optional): Country code (default: \"ANY\").\n            state (str, optional): State code (default: \"\").\n            city (str, optional): City name (default: \"\").\n            protocol (str, optional): Proxy protocol (\"http\" or \"socks5\"). Defaults to \"http\".\n            session_duration (int, optional): Session duration in minutes (0 = rotate each request). Defaults to 10.\n\n        Raises:\n            ValueError: If the API response format is invalid.\n            PermissionError: If the API returns an error message.\n        \"\"\"\n\n        # --- Validate input early ---\n        if not token or not channel_id:\n            raise ValueError(\"[NSTProxy] token and channel_id are required\")\n\n        if protocol not in (\"http\", \"socks5\"):\n            raise ValueError(f\"[NSTProxy] Invalid protocol: {protocol}\")\n\n        # --- Build NSTProxy API URL ---\n        params = {\n            \"fType\": 2,\n            \"count\": 1,\n            \"channelId\": channel_id,\n            \"country\": country,\n            \"protocol\": protocol,\n            \"sessionDuration\": session_duration,\n            \"token\": token,\n        }\n        if state:\n            params[\"state\"] = state\n        if city:\n            params[\"city\"] = city","sourceCodeStart":1044,"sourceCodeEnd":1080,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/async_configs.py#L1044-L1080","documentation":"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.","triggerScenarios":"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`).","commonSituations":"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.","solutions":["Pass both required credentials: set_nstproxy(token=os.environ['NSTPROXY_TOKEN'], channel_id='your-channel')","If using env vars, verify they are set and non-empty before calling (print bool(os.getenv(...)))","Confirm your NSTProxy dashboard shows a valid channel id — channel_id comes from NSTProxy, not your account password"],"exampleFix":"// before\ncfg.set_nstproxy(channel_id=\"12345\")  # token missing\n// after\nimport os\ncfg.set_nstproxy(token=os.environ[\"NSTPROXY_TOKEN\"], channel_id=\"12345\")","handlingStrategy":"validation","validationCode":"import os\n\ndef nstproxy_ready():\n    return bool(os.getenv(\"NSTPROXY_TOKEN\")) and bool(os.getenv(\"NSTPROXY_CHANNEL_ID\"))\n\n# before config:\nassert nstproxy_ready(), \"NSTPROXY_TOKEN / NSTPROXY_CHANNEL_ID missing\"","typeGuard":null,"tryCatchPattern":"try:\n    cfg.set_nstproxy(token=t, channel_id=c)\nexcept ValueError as e:\n    if \"token and channel_id\" in str(e):\n        raise RuntimeError(f\"Missing NSTProxy credentials: {e}\") from e\n    raise","preventionTips":["Fail fast at app startup on missing NSTPROXY_* env vars","Wrap credential loading in one helper used everywhere","Never placeholder credentials in committed examples"],"tags":["proxy","credentials","validation","nstproxy"],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}