Skip to content

Instantly share code, notes, and snippets.

@zsnmwy
Last active January 11, 2026 12:49
Show Gist options
  • Select an option

  • Save zsnmwy/4e9bf0dfaf3dc658a4df56b3986c8f49 to your computer and use it in GitHub Desktop.

Select an option

Save zsnmwy/4e9bf0dfaf3dc658a4df56b3986c8f49 to your computer and use it in GitHub Desktop.
File Location ~/.config/opencode/plugin/codex-proxy-plugin.ts
import type { Plugin } from '@opencode-ai/plugin';
/**
* Custom fetch wrapper that removes max_output_tokens and max_completion_tokens
* from the request body before sending to the API.
*
* @param input - The request URL or Request object
* @param init - Optional request init options
* @returns The fetch response
*/
async function codexFetch(input: Request | string | URL, init?: RequestInit): Promise<Response> {
if (!init?.body || typeof init.body !== 'string') {
return globalThis.fetch(input, init);
}
try {
const originalBody = JSON.parse(init.body);
// Remove token limit parameters that may cause issues
delete originalBody.max_output_tokens;
delete originalBody.max_completion_tokens;
const modifiedInit: RequestInit = {
...init,
body: JSON.stringify(originalBody),
};
return globalThis.fetch(input, modifiedInit);
} catch {
// If JSON parsing fails, proceed with original request
return globalThis.fetch(input, init);
}
}
/**
* Codex Proxy Plugin
*
* Intercepts requests to OpenCode providers and applies custom fetch handling
* to modify request parameters before they are sent to the API.
*/
export const CodexProxyPlugin: Plugin = async () => {
return {
config: async (input) => {
// const provider = input.provider?.['openai-duckcoding'];
const provider = input.provider?.['openai'];
if (provider) {
if (!provider.options) {
provider.options = {};
}
provider.options.fetch = codexFetch;
}
},
};
};
export default CodexProxyPlugin;
@zsnmwy
Copy link
Author

zsnmwy commented Jan 11, 2026

"openai": {
      "options": {
        "baseURL": "https://jp.duckcoding.com/v1"
      },
      "models": {
        "gpt-5.2": {
          "options": {
            "include": [
              "reasoning.encrypted_content"
            ],
            "store": false,
            "reasoningEffort": "high",
            "textVerbosity": "high",
            "reasoningSummary": "auto"
          }
        }
      }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment