{"record":{"id":"b90240dae20cfc4e","repo":"chenhg5/cc-connect","slug":"request-usage-endpoint-w","errorCode":null,"errorMessage":"request usage endpoint: %w","messagePattern":"request usage endpoint: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/codex/usage.go","lineNumber":104,"sourceCode":"\n\treturn codexOAuthTokens{\n\t\tAccessToken: payload.Tokens.AccessToken,\n\t\tAccountID:   payload.Tokens.AccountID,\n\t}, nil\n}\n\nfunc (a *Agent) fetchUsage(ctx context.Context, client *http.Client, tokens codexOAuthTokens) (*core.UsageReport, error) {\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, codexUsageURL, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treq.Header.Set(\"Authorization\", \"Bearer \"+tokens.AccessToken)\n\treq.Header.Set(\"ChatGPT-Account-Id\", tokens.AccountID)\n\treq.Header.Set(\"User-Agent\", \"codex-cli\")\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"request usage endpoint: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tbody, _ := io.ReadAll(io.LimitReader(resp.Body, 512))\n\t\treturn nil, fmt.Errorf(\"usage endpoint returned status %d: %s\", resp.StatusCode, strings.TrimSpace(string(body)))\n\t}\n\n\tvar payload codexUsageResponse\n\tif err := json.NewDecoder(resp.Body).Decode(&payload); err != nil {\n\t\treturn nil, fmt.Errorf(\"decode usage response: %w\", err)\n\t}\n\n\treturn mapCodexUsage(payload), nil\n}\n\nfunc mapCodexUsage(payload codexUsageResponse) *core.UsageReport {\n\treport := &core.UsageReport{","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/codex/usage.go#L86-L122","documentation":"fetchUsage performs an HTTP GET to the Codex/ChatGPT usage endpoint using the OAuth bearer token and account id. This error wraps any transport-level failure from client.Do — DNS failure, connection refused/reset, TLS errors, timeouts — before an HTTP response is available. It is thrown whenever the usage endpoint cannot be reached at all.","triggerScenarios":"client.Do(req) returns err inside fetchUsage, called from GetUsage with valid tokens read from auth.json: network unreachable, proxy misconfigured, DNS failure, TLS interception, or request context timeout.","commonSituations":"Offline or firewalled environments blocking chatgpt.com; corporate proxies requiring configuration (HTTPS_PROXY) not set for the daemon; VPN required; IPv6/DNS issues in containers; long-running bridge whose connections break after network changes.","solutions":["Verify basic connectivity: `curl -v https://chatgpt.com/backend-api/...` from the same host/user","Check proxy env vars (HTTPS_PROXY/HTTP_PROXY/NO_PROXY) are set for the process running cc-connect","Confirm DNS resolves inside containers/VPNs; test `getent hosts chatgpt.com`","Retry after network recovery; if behind a firewall, allowlist the usage endpoint host"],"exampleFix":"// before: no network pre-check, opaque failure\nusage, err := agent.GetUsage(ctx)\n// after: fail fast with a clear message\nif err := probeHTTPS(\"https://chatgpt.com\"); err != nil {\n    log.Fatalf(\"network unreachable for codex usage endpoint: %v (check proxy/VPN)\", err)\n}\nusage, err := agent.GetUsage(ctx)","handlingStrategy":"retry","validationCode":"conn, err := net.DialTimeout(\"tcp\", \"chatgpt.com:443\", 3*time.Second)\nif err != nil { return fmt.Errorf(\"usage endpoint unreachable: %w\", err) }\nconn.Close()","typeGuard":null,"tryCatchPattern":"report, err := agent.GetUsage(ctx)\nif err != nil && strings.Contains(err.Error(), \"request usage endpoint\") {\n    // transient transport failure: retry with backoff\n    return retryWithBackoff(3, 2*time.Second, func() error { _, err = agent.GetUsage(ctx); return err })\n}","preventionTips":["Set HTTPS_PROXY/NO_PROXY correctly for the daemon process","Allowlist the usage endpoint host in firewalls/VPNs","Use context.WithTimeout for predictable cancellation","Monitor connectivity from the same host/user as cc-connect"],"tags":["go","network","http","codex"],"backgroundTag":"network-request-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}