Skip to content

Commit 4654fb8

Browse files
fix: max output tokens when setting budget thinking tokens (#2056)
Co-authored-by: rekram1-node <[email protected]>
1 parent e915a37 commit 4654fb8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/opencode/src/provider/transform.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,18 @@ export namespace ProviderTransform {
9898
}
9999
return result
100100
}
101+
102+
export function maxOutputTokens(providerID: string, outputLimit: number, options: Record<string, any>): number {
103+
if (providerID === "anthropic") {
104+
const thinking = options["thinking"]
105+
if (typeof thinking === "object" && thinking !== null) {
106+
const type = thinking["type"]
107+
const budgetTokens = thinking["budgetTokens"]
108+
if (type === "enabled" && typeof budgetTokens === "number" && budgetTokens > 0) {
109+
return outputLimit - budgetTokens
110+
}
111+
}
112+
}
113+
return outputLimit
114+
}
101115
}

packages/opencode/src/session/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ export namespace Session {
10191019
: undefined,
10201020
maxRetries: 3,
10211021
activeTools: Object.keys(tools).filter((x) => x !== "invalid"),
1022-
maxOutputTokens: outputLimit,
1022+
maxOutputTokens: ProviderTransform.maxOutputTokens(model.providerID, outputLimit, params.options),
10231023
abortSignal: abort.signal,
10241024
stopWhen: async ({ steps }) => {
10251025
if (steps.length >= 1000) {

0 commit comments

Comments
 (0)