{"record":{"id":"a7bf95d5b42d041f","repo":"XX-net/XX-Net","slug":"x-tunnel-request-balance-fail-when-create-conn-s","errorCode":null,"errorMessage":"x-tunnel request_balance fail when create_conn:%s","messagePattern":"x-tunnel request_balance fail when create_conn:(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"code/default/x_tunnel/local/openai_handler.py","lineNumber":45,"sourceCode":"    json_str = utils.to_bytes(json.dumps(info))\n    token = base64.b64encode(json_str)\n    return \"Bearer \" + utils.to_str(token)\n\n\nauth_str = None\n\n\ndef get_openai_proxy(get_next_one=False):\n    global host\n    if get_next_one or not host:\n\n        if not (g.config.login_account and g.config.login_password):\n            return False\n\n        for _ in range(0, 3):\n            res, reason = proxy_session.request_balance(g.config.login_account, g.config.login_password)\n            if not res:\n                xlog.warn(\"x-tunnel request_balance fail when create_conn:%s\", reason)\n                time.sleep(1)\n\n        if not g.openai_proxies:\n            return None\n\n        host = random.choice(g.openai_proxies)\n    return host\n\n\ndef handle_openai(method, path, headers, req_body, sock):\n    global auth_str\n    if not auth_str:\n        auth_str = get_auth_str()\n\n    host = get_openai_proxy()\n    if not host:\n        # return sock.send(b'HTTP/1.1 401 Fail\\r\\n\\r\\n')\n        return 401, {}, \"Service not available at current status.\"","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/x_tunnel/local/openai_handler.py#L27-L63","documentation":"get_openai_proxy() tried up to 3 times to log in / request balance via x-tunnel (proxy_session.request_balance) and each attempt failed with the given reason. It indicates login or connectivity to the x-tunnel billing/login endpoint failing.","triggerScenarios":"Calling the OpenAI proxy path with g.config.login_account/login_password set, but request_balance returns failure 3 times: wrong credentials, server unreachable, or account out of quota.","commonSituations":"Expired xx-net account, wrong login/password in config, x-tunnel server down, or network blocking the login front.","solutions":["Verify login_account/login_password are correct for the xx-net account","Check the 'reason' string — it usually distinguishes auth vs network failure","Ensure other x-tunnel requests work (fronts alive, error 223 absent)","Retry after confirming the account has balance on the xx-net site"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"res, reason = proxy_session.request_balance(g.config.login_account, g.config.login_password)\nif not res and 'auth' in reason: fix_credentials()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate credentials before enabling OpenAI proxy","Check account balance periodically"],"tags":["x-tunnel","openai","login","balance"],"backgroundTag":"authentication-or-balance-failure","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}