Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/opencode/src/provider/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,18 @@ export namespace Provider {
export type Info = z.infer<typeof Info>

function fromModelsDevModel(provider: ModelsDev.Provider, model: ModelsDev.Model): Model {
const limit = iife(() => {
if (!provider.id.startsWith("github-copilot")) return model.limit
if (model.id !== "gpt-5.2" && model.id !== "gpt-5.2-codex") return model.limit

// models.dev currently reports incorrect limits for these Copilot models, causing premature compaction.
return {
...model.limit,
context: 400000,
input: 272000,
output: 128000,
}
})
const m: Model = {
id: model.id,
providerID: provider.id,
Expand Down Expand Up @@ -649,9 +661,9 @@ export namespace Provider {
: undefined,
},
limit: {
context: model.limit.context,
input: model.limit.input,
output: model.limit.output,
context: limit.context,
input: limit.input,
output: limit.output,
},
capabilities: {
temperature: model.temperature,
Expand Down
37 changes: 37 additions & 0 deletions packages/opencode/test/provider/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2148,3 +2148,40 @@ test("custom model with variants enabled and disabled", async () => {
},
})
})

test("github-copilot gpt-5.2 and gpt-5.2-codex token limits are overridden", async () => {
await using tmp = await tmpdir({
init: async (dir) => {
await Bun.write(
path.join(dir, "opencode.json"),
JSON.stringify({
$schema: "https://opencode.ai/config.json",
}),
)
},
})

await Instance.provide({
directory: tmp.path,
init: async () => {
Env.set("GITHUB_TOKEN", "test-token")
},
fn: async () => {
const providers = await Provider.list()
const copilot = providers["github-copilot"]
expect(copilot).toBeDefined()

const gpt52 = copilot.models["gpt-5.2"]
expect(gpt52).toBeDefined()
expect(gpt52.limit.context).toBe(400000)
expect(gpt52.limit.input).toBe(272000)
expect(gpt52.limit.output).toBe(128000)

const gpt52codex = copilot.models["gpt-5.2-codex"]
expect(gpt52codex).toBeDefined()
expect(gpt52codex.limit.context).toBe(400000)
expect(gpt52codex.limit.input).toBe(272000)
expect(gpt52codex.limit.output).toBe(128000)
},
})
})
Loading