summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYtzhak <[email protected]>2025-09-07 14:15:53 -0400
committerGitHub <[email protected]>2025-09-07 13:15:53 -0500
commit4654fb88de78e7fa45f7a09df6ec7ea79e54c2e8 (patch)
tree8fe4dcc2e97704bcaab7e671362f52d26596792b
parente915a3720e3187c0bd00ad208e7237f3368cc7cc (diff)
downloadopencode-4654fb88de78e7fa45f7a09df6ec7ea79e54c2e8.tar.gz
opencode-4654fb88de78e7fa45f7a09df6ec7ea79e54c2e8.zip
fix: max output tokens when setting budget thinking tokens (#2056)
Co-authored-by: rekram1-node <[email protected]>
-rw-r--r--packages/opencode/src/provider/transform.ts14
-rw-r--r--packages/opencode/src/session/index.ts2
2 files changed, 15 insertions, 1 deletions
diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts
index 50aa55cba..a9616cfd1 100644
--- a/packages/opencode/src/provider/transform.ts
+++ b/packages/opencode/src/provider/transform.ts
@@ -98,4 +98,18 @@ export namespace ProviderTransform {
}
return result
}
+
+ export function maxOutputTokens(providerID: string, outputLimit: number, options: Record<string, any>): number {
+ if (providerID === "anthropic") {
+ const thinking = options["thinking"]
+ if (typeof thinking === "object" && thinking !== null) {
+ const type = thinking["type"]
+ const budgetTokens = thinking["budgetTokens"]
+ if (type === "enabled" && typeof budgetTokens === "number" && budgetTokens > 0) {
+ return outputLimit - budgetTokens
+ }
+ }
+ }
+ return outputLimit
+ }
}
diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts
index 8093f58a0..113cf67bf 100644
--- a/packages/opencode/src/session/index.ts
+++ b/packages/opencode/src/session/index.ts
@@ -1019,7 +1019,7 @@ export namespace Session {
: undefined,
maxRetries: 3,
activeTools: Object.keys(tools).filter((x) => x !== "invalid"),
- maxOutputTokens: outputLimit,
+ maxOutputTokens: ProviderTransform.maxOutputTokens(model.providerID, outputLimit, params.options),
abortSignal: abort.signal,
stopWhen: async ({ steps }) => {
if (steps.length >= 1000) {