diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts index ef822739dd5b..4f32d5b5fd5a 100644 --- a/packages/opencode/src/provider/provider.ts +++ b/packages/opencode/src/provider/provider.ts @@ -11,6 +11,7 @@ import { Plugin } from "../plugin" import { NamedError } from "@opencode-ai/util/error" import { type LanguageModelV3 } from "@ai-sdk/provider" import { ModelsDev } from "./models" +import { ProviderTransform } from "./transform" import { Auth } from "../auth" import { Env } from "../env" import { Instance } from "../project/instance" @@ -55,7 +56,6 @@ import { } from "gitlab-ai-provider" import { fromNodeProviderChain } from "@aws-sdk/credential-providers" import { GoogleAuth } from "google-auth-library" -import { ProviderTransform } from "./transform" import { Installation } from "../installation" import { ModelID, ProviderID } from "./schema" @@ -1163,7 +1163,7 @@ export namespace Provider { 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/pr-body.md b/pr-body.md new file mode 100644 index 000000000000..185c6af624af --- /dev/null +++ b/pr-body.md @@ -0,0 +1,26 @@ +### Issue for this PR + +Closes #22253 + +### Type of change + +- [x] Bug fix + +### What does this PR do? + +Fixes custom provider models failing with "maxOutputTokens must be >= 1" when limit field is not defined. + +The issue was in `provider.ts` custom model parsing where models without a `limit` field fell back to 0 instead of `OUTPUT_TOKEN_MAX` (32000). Changed the fallback to use `ProviderTransform.OUTPUT_TOKEN_MAX`, consistent with built-in models. + +This is a different approach from PR #22016 which fixed the same issue in the `transform.ts` `maxOutputTokens()` function. This fix addresses it at the provider config parsing level. + +### How did you verify my code works? + +- Analyzed the code to understand the fallback logic +- Confirmed built-in models use `OUTPUT_TOKEN_MAX` as fallback +- Changed custom model parsing to use the same fallback + +### Checklist + +- [x] I have tested my changes locally +- [x] I have not included unrelated changes in this PR