跳到主要内容
    ↑↓ 选择↵ 打开esc 关闭
    中文English
    alexandru

    Openai Oauth Proxy

    v0.2.1认证与凭证
    opencode-openai-oauth-proxy

    OpenCode plugin that proxies OpenAI OAuth authentication and Codex API calls through a user-specified proxy server

    GitHub 星标

    0

    月装机量

    21

    近 7 天 5

    综合评分SCORE

    24.5

    生态多维模型

    最近提交

    2 个月前

    2026-06-07

    快速安装与配置

    opencode.json

    写入当前项目的 opencode.json,只对这个仓库生效。

    opencode.json

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["opencode-openai-oauth-proxy@0.2.1"]
    }

    opencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。

    OpenCode plugin that proxies OpenAI OAuth authentication and Codex API calls through a user-specified proxy server. Useful when you are behind a network that blocks direct connections to auth.openai.com and chatgpt.com.

    Installation

    Add the plugin to your opencode.json:

    {
      "plugin": [
        ["opencode-openai-oauth-proxy", {
          "routeMap": {
            "https://auth.openai.com/": "https://proxy.example.com/openai-auth/",
            "https://chatgpt.com/backend-api/": "https://proxy.example.com/openai-codex-api/"
          }
        }]
      ]
    }
    

    Then run opencode providers login --provider openai and select one of the proxied auth methods.

    Configuration

    The plugin accepts a single option — routeMap — which is a dictionary mapping original URLs to proxy URLs. All requests to URLs starting with a key are rewritten to use the corresponding value prefix, with the remaining path preserved.

    Required routes

    Original URL Proxy URL Purpose
    https://auth.openai.com/ Your proxy prefix OAuth authorize, token exchange, token refresh, device flow
    https://chatgpt.com/backend-api/ Your proxy prefix Codex LLM API calls

    Proxy server setup

    Your proxy server must transparently forward HTTPS requests. For example, if your proxy runs at proxy.example.com and uses prefix-based routing:

    /openai-auth/       → https://auth.openai.com/
    /openai-codex-api/  → https://chatgpt.com/backend-api/
    

    The proxy must preserve all HTTP headers, query parameters, and request bodies.

    Complete opencode.json example

    {
      "plugin": [
        ["opencode-openai-oauth-proxy", {
          "routeMap": {
            "https://auth.openai.com/": "https://proxy.example.com/openai-auth/",
            "https://chatgpt.com/backend-api/": "https://proxy.example.com/openai-codex-api/"
          }
        }]
      ],
      "provider": {
        "kimi-for-coding": {
          "options": {
            "baseURL": "https://proxy.example.com/km/v1"
          }
        },
        "opencode-go": {
          "options": {
            "baseURL": "https://proxy.example.com/go/v1"
          }
        }
      }
    }
    

    Authentication

    After adding the plugin, run:

    opencode providers login --provider openai
    

    You will see the proxied auth methods:

    • ChatGPT Pro/Plus (browser, proxied) — Opens a browser window. The authorization page loads through your proxy.
    • ChatGPT Pro/Plus (headless, proxied) — Device code flow for headless environments. All polling and token exchange goes through your proxy.
    • Manually enter API Key — Unchanged. No proxy needed for API keys.

    How it works

    The plugin overrides the built-in Codex OAuth methods using OpenCode's plugin system (external plugins take precedence over built-in ones for the same provider). All hardcoded auth.openai.com and chatgpt.com URLs are rewritten to use your proxy server.

    The plugin does not interfere with:

    • Other providers in your config
    • The built-in Codex model filtering (provider.models hook)
    • Chat headers and parameters (chat.headers, chat.params)

    Disabling the built-in plugin

    If you want only the proxy plugin's auth methods and not the built-in ones, set the environment variable:

    OPENCODE_DISABLE_DEFAULT_PLUGINS=true
    

    This is optional — even without it, the proxy plugin's auth methods replace the built-in ones because external plugins win when both register for the same provider.

    Building from source

    make build
    

    Publishing

    make publish
    

    Requires an npm token with publish access.

    License

    MIT