Skip to content

Add proxy support for API requests #341

@zergzorg

Description

@zergzorg

Problem

Add proxy support for API requests (Codex / Claude usage endpoints fail behind restricted regions)


Description

I’m using OpenUsage to track usage for Codex and Claude, but the plugins cannot fetch data due to network restrictions.

Both Codex and Claude themselves work correctly on my machine when routed through a proxy, but OpenUsage does not appear to use the same proxy settings, which results in failed API calls.


Expected behavior

OpenUsage should support routing its HTTP requests through a proxy (HTTP/SOCKS), so that usage endpoints can be accessed in restricted environments.

Ideally:

  • Respect standard environment variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY)
  • Or provide a built-in proxy configuration in settings (host, port, auth if needed)

Actual behavior

Both Codex and Claude plugins consistently fail with HTTP 403 errors when attempting to fetch usage data.

From logs:

Codex

POST https://auth.openai.com/oauth/token -> 403
{
  "error": {
    "code": "unsupported_country_region_territory",
    "message": "Country, region, or territory not supported"
  }
}

Claude

GET https://api.anthropic.com/api/oauth/usage -> 403
{
  "error": {
    "type": "forbidden",
    "message": "Request not allowed"
  }
}

The plugins attempt token refresh, but refresh also fails with 403.


Important context

  • Codex CLI / ChatGPT / Claude all work correctly on this machine when routed through a proxy
  • The issue only occurs inside OpenUsage
  • This strongly suggests that OpenUsage is making direct requests instead of using the system or environment proxy

Why this matters

In restricted or geo-limited environments, proxy routing is required for:

  • OAuth token refresh
  • Usage/statistics endpoints

Without proxy support, the core functionality of OpenUsage (tracking usage) becomes unavailable for these providers.


Suggested solution

One of the following would solve the issue:

  1. Support standard environment variables:

    • HTTP_PROXY
    • HTTPS_PROXY
    • ALL_PROXY
    • NO_PROXY
  2. Add explicit proxy configuration in the app:

    • Proxy type (HTTP / SOCKS5)
    • Host / port
    • Optional authentication
  3. Ensure all plugin HTTP clients use a shared configurable transport layer


Additional notes

  • The issue is reproducible 100% of the time without proxy
  • Likely related to region-based restrictions (as indicated by OpenAI error)
  • Other plugins (e.g. Google-based endpoints) work fine, suggesting general networking is OK

Proposed Solution

OpenUsage should support proxy configuration for all outbound HTTP requests made by plugins.

Suggested implementation:

  1. Respect standard environment variables

    • Automatically use HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, and NO_PROXY if they are set
    • This allows compatibility with existing setups (e.g. CLI tools like Codex/Claude)
  2. Provide optional in-app proxy settings

    • Proxy type: HTTP / SOCKS5
    • Host and port
    • Optional authentication (username/password)
    • If configured, these settings should override environment variables
  3. Centralize HTTP client configuration

    • All plugins (codex, claude, etc.) should use a shared HTTP client or transport layer
    • Proxy settings should be applied globally to this client to ensure consistent behavior
  4. Add basic diagnostics (optional but useful)

    • Log whether proxy is being used for each request
    • This would simplify debugging in restricted environments

This would allow OpenUsage to function correctly in environments where direct access to provider APIs is restricted, but proxy access is available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions