Skip to content

Commit 6197b68

Browse files
kiennqgithub-actions[bot]
authored andcommitted
fix(config): honor model limit.input overrides (upstream PR anomalyco#16306)
1 parent 207f9d8 commit 6197b68

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

packages/opencode/src/config/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ export namespace Config {
937937
.record(
938938
z.string(),
939939
ModelsDev.Model.partial().extend({
940+
limit: ModelsDev.Model.shape.limit.partial().optional(),
940941
variants: z
941942
.record(
942943
z.string(),

packages/opencode/src/provider/provider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@ export namespace Provider {
894894
options: mergeDeep(existingModel?.options ?? {}, model.options ?? {}),
895895
limit: {
896896
context: model.limit?.context ?? existingModel?.limit?.context ?? 0,
897+
input: model.limit?.input ?? existingModel?.limit?.input,
897898
output: model.limit?.output ?? existingModel?.limit?.output ?? 0,
898899
},
899900
headers: mergeDeep(existingModel?.headers ?? {}, model.headers ?? {}),

packages/opencode/test/provider/provider.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,85 @@ test("model inherits properties from existing database model", async () => {
750750
})
751751
})
752752

753+
test("existing model supports partial limit.input override", async () => {
754+
await using tmp = await tmpdir({
755+
init: async (dir) => {
756+
await Bun.write(
757+
path.join(dir, "opencode.json"),
758+
JSON.stringify({
759+
$schema: "https://opencode.ai/config.json",
760+
provider: {
761+
anthropic: {
762+
models: {
763+
"claude-sonnet-4-20250514": {
764+
limit: {
765+
input: 123456,
766+
},
767+
},
768+
},
769+
},
770+
},
771+
}),
772+
)
773+
},
774+
})
775+
await Instance.provide({
776+
directory: tmp.path,
777+
init: async () => {
778+
Env.set("ANTHROPIC_API_KEY", "test-api-key")
779+
},
780+
fn: async () => {
781+
const providers = await Provider.list()
782+
const model = providers["anthropic"].models["claude-sonnet-4-20250514"]
783+
expect(model.limit.input).toBe(123456)
784+
expect(model.limit.context).toBeGreaterThan(0)
785+
expect(model.limit.output).toBeGreaterThan(0)
786+
},
787+
})
788+
})
789+
790+
test("custom model preserves configured limit.input", async () => {
791+
await using tmp = await tmpdir({
792+
init: async (dir) => {
793+
await Bun.write(
794+
path.join(dir, "opencode.json"),
795+
JSON.stringify({
796+
$schema: "https://opencode.ai/config.json",
797+
provider: {
798+
"custom-input-limit": {
799+
name: "Custom Input Limit",
800+
npm: "@ai-sdk/openai-compatible",
801+
env: [],
802+
models: {
803+
model: {
804+
name: "Model",
805+
tool_call: true,
806+
limit: {
807+
context: 128000,
808+
input: 64000,
809+
output: 4096,
810+
},
811+
},
812+
},
813+
options: { apiKey: "test" },
814+
},
815+
},
816+
}),
817+
)
818+
},
819+
})
820+
await Instance.provide({
821+
directory: tmp.path,
822+
fn: async () => {
823+
const providers = await Provider.list()
824+
const model = providers["custom-input-limit"].models["model"]
825+
expect(model.limit.context).toBe(128000)
826+
expect(model.limit.input).toBe(64000)
827+
expect(model.limit.output).toBe(4096)
828+
},
829+
})
830+
})
831+
753832
test("disabled_providers prevents loading even with env var", async () => {
754833
await using tmp = await tmpdir({
755834
init: async (dir) => {

0 commit comments

Comments
 (0)