diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts index d643f25373af..32781faa3124 100644 --- a/packages/opencode/src/provider/provider.ts +++ b/packages/opencode/src/provider/provider.ts @@ -1192,7 +1192,7 @@ const layer: Layer.Layer< limit: { context: model.limit?.context ?? existingModel?.limit?.context ?? 0, input: model.limit?.input ?? existingModel?.limit?.input, - output: model.limit?.output ?? existingModel?.limit?.output ?? 0, + output: model.limit?.output ?? existingModel?.limit?.output ?? ProviderTransform.OUTPUT_TOKEN_MAX, }, headers: mergeDeep(existingModel?.headers ?? {}, model.headers ?? {}), family: model.family ?? existingModel?.family ?? "", diff --git a/packages/opencode/test/provider/provider.test.ts b/packages/opencode/test/provider/provider.test.ts index 8993020820e3..9ed2c001a08e 100644 --- a/packages/opencode/test/provider/provider.test.ts +++ b/packages/opencode/test/provider/provider.test.ts @@ -8,6 +8,7 @@ import { Instance } from "../../src/project/instance" import { Plugin } from "../../src/plugin/index" import { ModelsDev } from "../../src/provider" import { Provider } from "../../src/provider" +import { OUTPUT_TOKEN_MAX } from "../../src/provider/transform" import { ProviderID, ModelID } from "../../src/provider/schema" import { Filesystem } from "../../src/util" import { Env } from "../../src/env" @@ -1745,7 +1746,7 @@ test("model limit defaults to zero when not specified", async () => { const providers = await list() const model = providers[ProviderID.make("no-limit")].models["model"] expect(model.limit.context).toBe(0) - expect(model.limit.output).toBe(0) + expect(model.limit.output).toBe(OUTPUT_TOKEN_MAX) }, }) }) @@ -2640,3 +2641,38 @@ test("opencode loader keeps paid models when auth exists", async () => { } } }) + +test("custom model without output limit falls back to OUTPUT_TOKEN_MAX", 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", + provider: { + "custom-provider": { + name: "Custom Provider", + npm: "@ai-sdk/openai-compatible", + env: [], + models: { + "custom-model": { + name: "Custom Model", + tool_call: true, + }, + }, + options: { apiKey: "test" }, + }, + }, + }), + ) + }, + }) + await Instance.provide({ + directory: tmp.path, + fn: async () => { + const providers = await list() + const model = providers[ProviderID.make("custom-provider")].models["custom-model"] + expect(model.limit.output).toBe(OUTPUT_TOKEN_MAX) + }, + }) +})