@@ -1578,4 +1578,189 @@ export function schema(model: Provider.Model, schema: JSONSchema7): JSONSchema7
15781578 return schema
15791579}
15801580
1581+ export function reasoningVariants ( model : ModelsDev . Model , target : Provider . Model ) : Provider . Model [ "variants" ] {
1582+ const options = model . reasoning_options
1583+ if ( options === undefined ) return
1584+ if ( options . length === 0 ) return { }
1585+
1586+ const effort = options . find ( ( option ) => option . type === "effort" )
1587+ if ( effort ) return nonEmptyVariants ( effortVariants ( target , effort . values ) )
1588+
1589+ const toggle = options . some ( ( option ) => option . type === "toggle" )
1590+ const budget = options . find ( ( option ) => option . type === "budget_tokens" )
1591+ if ( ! budget ) return toggle ? nonEmptyVariants ( reasoningToggle ( target ) ) : undefined
1592+
1593+ return nonEmptyVariants ( {
1594+ ...( toggle ? reasoningToggle ( target ) : { } ) ,
1595+ ...budgetVariants ( target , budget . min , budget . max ) ,
1596+ } )
1597+ }
1598+
1599+ function effortVariants ( model : Provider . Model , values : readonly unknown [ ] ) {
1600+ return Object . fromEntries (
1601+ values . flatMap ( ( value ) => {
1602+ const id = ( ( ) => {
1603+ if ( value === null ) return "none"
1604+ if ( typeof value === "string" ) return value
1605+ } ) ( )
1606+ if ( id === undefined ) return [ ]
1607+ const settings = reasoningEffort ( model , id )
1608+ return settings ? [ [ id , settings ] ] : [ ]
1609+ } ) ,
1610+ )
1611+ }
1612+
1613+ function budgetVariants ( model : Provider . Model , min ?: number , max ?: number ) {
1614+ const limit = model . limit . output - 1
1615+ if ( limit <= 0 ) return { }
1616+ const high = Math . min (
1617+ max === undefined ? Math . max ( min ?? 0 , 16_000 ) : Math . min ( Math . max ( min ?? 0 , 16_000 ) , max ) ,
1618+ limit ,
1619+ )
1620+ const maximum = max === undefined ? undefined : Math . min ( max , limit )
1621+ return Object . fromEntries (
1622+ [
1623+ { id : "high" , budget : high } ,
1624+ ...( maximum === undefined || maximum === high ? [ ] : [ { id : "max" , budget : maximum } ] ) ,
1625+ ] . flatMap ( ( item ) => {
1626+ const settings = reasoningBudget ( model , item . budget )
1627+ return settings ? [ [ item . id , settings ] ] : [ ]
1628+ } ) ,
1629+ )
1630+ }
1631+
1632+ function nonEmptyVariants ( variants : NonNullable < Provider . Model [ "variants" ] > ) : Provider . Model [ "variants" ] {
1633+ return Object . keys ( variants ) . length > 0 ? variants : undefined
1634+ }
1635+
1636+ function reasoningToggle ( model : Provider . Model ) : NonNullable < Provider . Model [ "variants" ] > {
1637+ if ( model . api . npm === "@ai-sdk/alibaba" )
1638+ return {
1639+ none : { enableThinking : false } ,
1640+ high : { enableThinking : true } ,
1641+ }
1642+ if ( model . api . npm === "@ai-sdk/cohere" )
1643+ return {
1644+ none : { thinking : { type : "disabled" } } ,
1645+ high : { thinking : { type : "enabled" } } ,
1646+ }
1647+ return { }
1648+ }
1649+
1650+ function reasoningEffort ( model : Provider . Model , effort : string ) {
1651+ switch ( model . api . npm ) {
1652+ case "@openrouter/ai-sdk-provider" :
1653+ return { reasoning : { effort } }
1654+ case "@ai-sdk/anthropic" :
1655+ case "@ai-sdk/google-vertex/anthropic" :
1656+ return anthropicEffort ( model , effort )
1657+ case "@ai-sdk/google" :
1658+ case "@ai-sdk/google-vertex" :
1659+ return { thinkingConfig : { includeThoughts : true , thinkingLevel : effort } }
1660+ case "@ai-sdk/amazon-bedrock" :
1661+ if ( anthropicAdaptiveEfforts ( model . api . id ) )
1662+ return {
1663+ reasoningConfig : {
1664+ type : "adaptive" ,
1665+ maxReasoningEffort : effort ,
1666+ ...( anthropicOmitsThinking ( model . api . id ) ? { display : "summarized" } : { } ) ,
1667+ } ,
1668+ }
1669+ if ( model . api . id . includes ( "anthropic" ) ) return
1670+ return { reasoningConfig : { type : "enabled" , maxReasoningEffort : effort } }
1671+ case "@ai-sdk/gateway" :
1672+ if ( model . id . includes ( "anthropic" ) ) return { thinking : { type : "adaptive" , display : "summarized" } , effort }
1673+ if ( model . id . includes ( "google" ) ) return { thinkingConfig : { includeThoughts : true , thinkingLevel : effort } }
1674+ return { reasoningEffort : effort }
1675+ case "@ai-sdk/github-copilot" :
1676+ // OAuth discovery replaces these with variants from Copilot's /models capabilities.
1677+ if ( model . id . includes ( "gemini" ) ) return
1678+ if ( model . id . includes ( "claude" ) ) return { reasoningEffort : effort }
1679+ return { reasoningEffort : effort , reasoningSummary : "auto" , include : INCLUDE_ENCRYPTED_REASONING }
1680+ case "@ai-sdk/openai" :
1681+ case "@ai-sdk/amazon-bedrock/mantle" :
1682+ return { reasoningEffort : effort , reasoningSummary : "auto" , include : INCLUDE_ENCRYPTED_REASONING }
1683+ case "@ai-sdk/azure" :
1684+ return { reasoningEffort : effort , reasoningSummary : "auto" , include : INCLUDE_ENCRYPTED_REASONING }
1685+ case "@jerome-benoit/sap-ai-provider-v2" :
1686+ if ( model . id . includes ( "anthropic" ) )
1687+ return { modelParams : { thinking : { type : "adaptive" , display : "summarized" } , output_config : { effort } } }
1688+ return { modelParams : { reasoning_effort : effort } }
1689+ case "@ai-sdk/openai-compatible" :
1690+ case "@ai-sdk/xai" :
1691+ case "@ai-sdk/mistral" :
1692+ case "@ai-sdk/groq" :
1693+ case "@ai-sdk/cerebras" :
1694+ case "@ai-sdk/deepinfra" :
1695+ case "@ai-sdk/togetherai" :
1696+ case "venice-ai-sdk-provider" :
1697+ case "ai-gateway-provider" :
1698+ return { reasoningEffort : effort }
1699+ case "@ai-sdk/cohere" :
1700+ case "@ai-sdk/perplexity" :
1701+ case "@ai-sdk/vercel" :
1702+ case "@ai-sdk/alibaba" :
1703+ case "gitlab-ai-provider" :
1704+ return
1705+ }
1706+ }
1707+
1708+ function anthropicEffort ( model : Provider . Model , effort : string ) {
1709+ if ( [ "opus-4-5" , "opus-4.5" ] . some ( ( value ) => model . api . id . includes ( value ) ) ) return { effort }
1710+ if ( ! anthropicAdaptiveEfforts ( model . api . id ) ) return
1711+ return {
1712+ thinking : {
1713+ type : "adaptive" ,
1714+ ...( anthropicOmitsThinking ( model . api . id ) ? { display : "summarized" } : { } ) ,
1715+ } ,
1716+ effort,
1717+ }
1718+ }
1719+
1720+ function reasoningBudget ( model : Provider . Model , budget : number ) {
1721+ switch ( model . api . npm ) {
1722+ case "@openrouter/ai-sdk-provider" :
1723+ return { reasoning : { max_tokens : budget } }
1724+ case "@ai-sdk/anthropic" :
1725+ case "@ai-sdk/google-vertex/anthropic" :
1726+ return { thinking : { type : "enabled" , budgetTokens : budget } }
1727+ case "@ai-sdk/google" :
1728+ case "@ai-sdk/google-vertex" :
1729+ return { thinkingConfig : { includeThoughts : true , thinkingBudget : budget } }
1730+ case "@ai-sdk/amazon-bedrock" :
1731+ return { reasoningConfig : { type : "enabled" , budgetTokens : budget } }
1732+ case "@ai-sdk/gateway" :
1733+ if ( model . id . includes ( "anthropic" ) ) return { thinking : { type : "enabled" , budgetTokens : budget } }
1734+ if ( model . id . includes ( "google" ) ) return { thinkingConfig : { includeThoughts : true , thinkingBudget : budget } }
1735+ return
1736+ case "@ai-sdk/cohere" :
1737+ return { thinking : { type : "enabled" , tokenBudget : budget } }
1738+ case "@ai-sdk/alibaba" :
1739+ return { enableThinking : true , thinkingBudget : budget }
1740+ case "@jerome-benoit/sap-ai-provider-v2" :
1741+ if ( model . id . includes ( "anthropic" ) )
1742+ return { modelParams : { thinking : { type : "enabled" , budget_tokens : budget } } }
1743+ if ( model . id . includes ( "gemini" ) )
1744+ return { modelParams : { thinkingConfig : { includeThoughts : true , thinkingBudget : budget } } }
1745+ return
1746+ case "@ai-sdk/amazon-bedrock/mantle" :
1747+ case "@ai-sdk/azure" :
1748+ case "@ai-sdk/cerebras" :
1749+ case "@ai-sdk/deepinfra" :
1750+ case "@ai-sdk/github-copilot" :
1751+ case "@ai-sdk/groq" :
1752+ case "@ai-sdk/mistral" :
1753+ case "@ai-sdk/openai" :
1754+ case "@ai-sdk/openai-compatible" :
1755+ case "@ai-sdk/perplexity" :
1756+ case "@ai-sdk/togetherai" :
1757+ case "@ai-sdk/vercel" :
1758+ case "@ai-sdk/xai" :
1759+ case "ai-gateway-provider" :
1760+ case "gitlab-ai-provider" :
1761+ case "venice-ai-sdk-provider" :
1762+ return
1763+ }
1764+ }
1765+
15811766export * as ProviderTransform from "./transform"
0 commit comments