XX-net/XX-Net · error

x-tunnel request_balance fail when create_conn:%s

Error message

x-tunnel request_balance fail when create_conn:%s

What it means

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.

Source

Thrown at code/default/x_tunnel/local/openai_handler.py:45

    json_str = utils.to_bytes(json.dumps(info))
    token = base64.b64encode(json_str)
    return "Bearer " + utils.to_str(token)


auth_str = None


def get_openai_proxy(get_next_one=False):
    global host
    if get_next_one or not host:

        if not (g.config.login_account and g.config.login_password):
            return False

        for _ in range(0, 3):
            res, reason = proxy_session.request_balance(g.config.login_account, g.config.login_password)
            if not res:
                xlog.warn("x-tunnel request_balance fail when create_conn:%s", reason)
                time.sleep(1)

        if not g.openai_proxies:
            return None

        host = random.choice(g.openai_proxies)
    return host


def handle_openai(method, path, headers, req_body, sock):
    global auth_str
    if not auth_str:
        auth_str = get_auth_str()

    host = get_openai_proxy()
    if not host:
        # return sock.send(b'HTTP/1.1 401 Fail\r\n\r\n')
        return 401, {}, "Service not available at current status."

View on GitHub (pinned to cfa5bc17b6)

Solutions

  1. Verify login_account/login_password are correct for the xx-net account
  2. Check the 'reason' string — it usually distinguishes auth vs network failure
  3. Ensure other x-tunnel requests work (fronts alive, error 223 absent)
  4. Retry after confirming the account has balance on the xx-net site
Defensive patterns

Strategy: retry

Validate before calling

res, reason = proxy_session.request_balance(g.config.login_account, g.config.login_password)
if not res and 'auth' in reason: fix_credentials()

Prevention

When it happens

Trigger: 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.

Common situations: Expired xx-net account, wrong login/password in config, x-tunnel server down, or network blocking the login front.

Related errors


AI-assisted analysis of XX-net/XX-Net@cfa5bc17b6 (2026-08-27). Data as JSON: /api/errors/a7bf95d5b42d041f. Report an issue: GitHub.