{"record":{"id":"82cc77dbc732f7ec","repo":"oobabooga/textgen","slug":"you-must-enable-ipv6-or-ipv4-for-the-api-to-work","errorCode":null,"errorMessage":"you MUST enable IPv6 or IPv4 for the API to work","messagePattern":"you MUST enable IPv6 or IPv4 for the API to work","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"modules/api/script.py","lineNumber":576,"sourceCode":"def run_server():\n    # Parse configuration\n    port = int(os.environ.get('OPENEDAI_PORT', shared.args.api_port))\n    port = find_available_port(port)\n    ssl_certfile = os.environ.get('OPENEDAI_CERT_PATH', shared.args.ssl_certfile)\n    ssl_keyfile = os.environ.get('OPENEDAI_KEY_PATH', shared.args.ssl_keyfile)\n\n    # In the server configuration:\n    server_addrs = []\n    if shared.args.listen and shared.args.listen_host:\n        server_addrs.append(shared.args.listen_host)\n    else:\n        if os.environ.get('OPENEDAI_ENABLE_IPV6', shared.args.api_enable_ipv6):\n            server_addrs.append('::' if shared.args.listen else '::1')\n        if not os.environ.get('OPENEDAI_DISABLE_IPV4', shared.args.api_disable_ipv4):\n            server_addrs.append('0.0.0.0' if shared.args.listen else '127.0.0.1')\n\n    if not server_addrs:\n        raise Exception('you MUST enable IPv6 or IPv4 for the API to work')\n\n    # Log server information\n    if shared.args.public_api:\n        _start_cloudflared(\n            port,\n            shared.args.public_api_id,\n            max_attempts=3,\n            on_start=lambda url: logger.info(f'OpenAI/Anthropic-compatible API URL:\\n\\n{url}/v1\\n')\n        )\n    else:\n        url_proto = 'https://' if (ssl_certfile and ssl_keyfile) else 'http://'\n        urls = [f'{url_proto}[{addr}]:{port}/v1' if ':' in addr else f'{url_proto}{addr}:{port}/v1' for addr in server_addrs]\n        if len(urls) > 1:\n            logger.info('OpenAI/Anthropic-compatible API URLs:\\n\\n' + '\\n'.join(urls) + '\\n')\n        else:\n            logger.info('OpenAI/Anthropic-compatible API URL:\\n\\n' + '\\n'.join(urls) + '\\n')\n\n    # Log API keys","sourceCodeStart":558,"sourceCodeEnd":594,"githubUrl":"https://github.com/oobabooga/textgen/blob/ed888c71f221df552750e1834b3654abab8ae345/modules/api/script.py#L558-L594","documentation":"Raised during API server startup (modules/api/script.py:576, run_server) when the bind-address list ends up empty: IPv6 was disabled (OPENEDAI_DISABLE_IPV4 unset-false path inverted — specifically api_disable_ipv4 flag / OPENEDAI_DISABLE_IPV4 env truthy) AND IPv6 was not enabled (no --api-enable-ipv6 and OPENEDAI_ENABLE_IPV6 falsy). With no address family left, uvicorn has nothing to bind.","triggerScenarios":"Launching with --api --api-disable-ipv4 and neither --api-enable-ipv6 nor OPENEDAI_ENABLE_IPV6 set; or setting env OPENEDAI_DISABLE_IPV4=1 while relying on default IPv4-only binding.","commonSituations":"Users on IPv4-restricted networks disabling IPv4 to avoid dual-stack issues but forgetting the IPv6 flag; config drift after upgrading where --api-enable-ipv6 was dropped from the start script; docker setups passing only one of the two env vars.","solutions":["If you want IPv6-only: add --api-enable-ipv6 (or env OPENEDAI_ENABLE_IPV6=1) alongside --api-disable-ipv4.","If you want IPv4: remove --api-disable-ipv4 / unset OPENEDAI_DISABLE_IPV4 so the default 127.0.0.1 (or 0.0.0.0 with --listen) is used.","Prefer a single explicit --listen-host over juggling the v4/v6 toggles."],"exampleFix":"# before (startup flags)\npython server.py --api --api-disable-ipv4\n# -> Exception: you MUST enable IPv6 or IPv4 for the API to work\n\n# after\npython server.py --api --api-disable-ipv4 --api-enable-ipv6\n","handlingStrategy":"validation","validationCode":"import os\n\ndef validate_api_net_args(enable_ipv6: bool, disable_ipv4: bool) -> None:\n    if disable_ipv4 and not enable_ipv4_fallback():\n        raise SystemExit(\n            '--api-disable-ipv4 requires --api-enable-ipv6 '\n            '(or OPENEDAI_ENABLE_IPV6=1), otherwise there is no address to bind')\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set IPv4/IPv6 flags as an explicit pair in your start script; never ship only one toggle.","Prefer --listen-host <ip> when you need a specific address family; it bypasses the v4/v6 flag matrix entirely.","Smoke-test API startup in CI with the exact production flags."],"tags":["startup","network","ipv6","ipv4","config"],"backgroundTag":null,"analyzedSha":"ed888c71f221df552750e1834b3654abab8ae345","analyzedAt":"2026-08-15T05:24:21.000Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}