Something went wrong. Try again.
OpenCode plugins that adds 1 million context variants of OpenAI GPT models
Something went wrong. Try again.
1.4 kB · 40 lines · Created 1mo ago
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041import { Plugin } from "@opencode/plugin";
export default Plugin.define({ id: "gpt-long-context", async setup(ctx) { await ctx.model.transform((editor) => { // The built-in Codex plugin sets this endpoint and reloads on account changes. const source = editor.provider.get("openai"); if (source?.provider.settings?.baseURL !== "https://chatgpt.com/backend-api/codex") { return; }
for (const model of editor.list("openai")) { // Source limits precede Codex's 400K cap; enabled reflects its eligibility filter. const context = source.models.get(model.id)?.limit.context ?? 0; if (!model.enabled || model.id.endsWith("-1m") || context < 1_000_000) { continue; }
const longModelId = `${model.id}-1m`; if (editor.get("openai", longModelId)) { continue; }
// Keep the upstream modelID and request options; update assigns the alias ID. const output = model.limit.output; editor.update("openai", longModelId, (alias) => { Object.assign(alias, structuredClone(model), { name: `${model.name} (1M context)`, limit: { context: 1_000_000, input: 1_000_000 - output, output, }, }); }); } }); },});