@@ -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+
753832test ( "disabled_providers prevents loading even with env var" , async ( ) => {
754833 await using tmp = await tmpdir ( {
755834 init : async ( dir ) => {
0 commit comments