@@ -34,6 +34,12 @@ export interface ModelCapabilities {
3434 toolUsageControl ?: boolean
3535 computerUse ?: boolean
3636 nativeStructuredOutputs ?: boolean
37+ maxOutputTokens ?: {
38+ /** Maximum tokens for streaming requests */
39+ max : number
40+ /** Safe default for non-streaming requests (to avoid timeout issues) */
41+ default : number
42+ }
3743 reasoningEffort ?: {
3844 values : string [ ]
3945 }
@@ -613,6 +619,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
613619 capabilities : {
614620 temperature : { min : 0 , max : 1 } ,
615621 nativeStructuredOutputs : true ,
622+ maxOutputTokens : { max : 64000 , default : 4096 } ,
616623 } ,
617624 contextWindow : 200000 ,
618625 } ,
@@ -627,6 +634,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
627634 capabilities : {
628635 temperature : { min : 0 , max : 1 } ,
629636 nativeStructuredOutputs : true ,
637+ maxOutputTokens : { max : 64000 , default : 4096 } ,
630638 } ,
631639 contextWindow : 200000 ,
632640 } ,
@@ -640,6 +648,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
640648 } ,
641649 capabilities : {
642650 temperature : { min : 0 , max : 1 } ,
651+ maxOutputTokens : { max : 64000 , default : 4096 } ,
643652 } ,
644653 contextWindow : 200000 ,
645654 } ,
@@ -654,6 +663,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
654663 capabilities : {
655664 temperature : { min : 0 , max : 1 } ,
656665 nativeStructuredOutputs : true ,
666+ maxOutputTokens : { max : 64000 , default : 4096 } ,
657667 } ,
658668 contextWindow : 200000 ,
659669 } ,
@@ -668,6 +678,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
668678 capabilities : {
669679 temperature : { min : 0 , max : 1 } ,
670680 nativeStructuredOutputs : true ,
681+ maxOutputTokens : { max : 64000 , default : 4096 } ,
671682 } ,
672683 contextWindow : 200000 ,
673684 } ,
@@ -681,6 +692,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
681692 } ,
682693 capabilities : {
683694 temperature : { min : 0 , max : 1 } ,
695+ maxOutputTokens : { max : 64000 , default : 4096 } ,
684696 } ,
685697 contextWindow : 200000 ,
686698 } ,
@@ -695,6 +707,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
695707 capabilities : {
696708 temperature : { min : 0 , max : 1 } ,
697709 computerUse : true ,
710+ maxOutputTokens : { max : 8192 , default : 8192 } ,
698711 } ,
699712 contextWindow : 200000 ,
700713 } ,
@@ -709,6 +722,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
709722 capabilities : {
710723 temperature : { min : 0 , max : 1 } ,
711724 computerUse : true ,
725+ maxOutputTokens : { max : 8192 , default : 8192 } ,
712726 } ,
713727 contextWindow : 200000 ,
714728 } ,
@@ -1655,6 +1669,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
16551669 capabilities : {
16561670 temperature : { min : 0 , max : 1 } ,
16571671 nativeStructuredOutputs : true ,
1672+ maxOutputTokens : { max : 64000 , default : 4096 } ,
16581673 } ,
16591674 contextWindow : 200000 ,
16601675 } ,
@@ -1668,6 +1683,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
16681683 capabilities : {
16691684 temperature : { min : 0 , max : 1 } ,
16701685 nativeStructuredOutputs : true ,
1686+ maxOutputTokens : { max : 64000 , default : 4096 } ,
16711687 } ,
16721688 contextWindow : 200000 ,
16731689 } ,
@@ -1681,6 +1697,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
16811697 capabilities : {
16821698 temperature : { min : 0 , max : 1 } ,
16831699 nativeStructuredOutputs : true ,
1700+ maxOutputTokens : { max : 64000 , default : 4096 } ,
16841701 } ,
16851702 contextWindow : 200000 ,
16861703 } ,
@@ -1694,6 +1711,7 @@ export const PROVIDER_DEFINITIONS: Record<string, ProviderDefinition> = {
16941711 capabilities : {
16951712 temperature : { min : 0 , max : 1 } ,
16961713 nativeStructuredOutputs : true ,
1714+ maxOutputTokens : { max : 64000 , default : 4096 } ,
16971715 } ,
16981716 contextWindow : 200000 ,
16991717 } ,
@@ -2333,3 +2351,31 @@ export function getThinkingLevelsForModel(modelId: string): string[] | null {
23332351 const capability = getThinkingCapability ( modelId )
23342352 return capability ?. levels ?? null
23352353}
2354+
2355+ /**
2356+ * Get the max output tokens for a specific model
2357+ * Returns the model's max capacity for streaming requests,
2358+ * or the model's safe default for non-streaming requests to avoid timeout issues.
2359+ *
2360+ * @param modelId - The model ID
2361+ * @param streaming - Whether the request is streaming (default: false)
2362+ */
2363+ export function getMaxOutputTokensForModel ( modelId : string , streaming = false ) : number {
2364+ const normalizedModelId = modelId . toLowerCase ( )
2365+ const STANDARD_MAX_OUTPUT_TOKENS = 4096
2366+
2367+ for ( const provider of Object . values ( PROVIDER_DEFINITIONS ) ) {
2368+ for ( const model of provider . models ) {
2369+ const baseModelId = model . id . toLowerCase ( )
2370+ if ( normalizedModelId === baseModelId || normalizedModelId . startsWith ( `${ baseModelId } -` ) ) {
2371+ const outputTokens = model . capabilities . maxOutputTokens
2372+ if ( outputTokens ) {
2373+ return streaming ? outputTokens . max : outputTokens . default
2374+ }
2375+ return STANDARD_MAX_OUTPUT_TOKENS
2376+ }
2377+ }
2378+ }
2379+
2380+ return STANDARD_MAX_OUTPUT_TOKENS
2381+ }
0 commit comments