@@ -22,12 +22,15 @@ const openRouterEndpointsSchema = z.object({
2222 endpoints : z . array (
2323 z . object ( {
2424 name : z . string ( ) ,
25+ tag : z . string ( ) . optional ( ) ,
2526 context_length : z . number ( ) ,
2627 max_completion_tokens : z . number ( ) . nullish ( ) ,
2728 pricing : z
2829 . object ( {
2930 prompt : z . union ( [ z . string ( ) , z . number ( ) ] ) . optional ( ) ,
3031 completion : z . union ( [ z . string ( ) , z . number ( ) ] ) . optional ( ) ,
32+ input_cache_read : z . union ( [ z . string ( ) , z . number ( ) ] ) . optional ( ) ,
33+ input_cache_write : z . union ( [ z . string ( ) , z . number ( ) ] ) . optional ( ) ,
3134 } )
3235 . optional ( ) ,
3336 } ) ,
@@ -51,49 +54,28 @@ async function getOpenRouterProvidersForModel(modelId: string) {
5154 return models
5255 }
5356
54- const { id , description, architecture, endpoints } = result . data . data
57+ const { description, architecture, endpoints } = result . data . data
5558
5659 for ( const endpoint of endpoints ) {
57- const providerName = endpoint . name . split ( "|" ) [ 0 ] . trim ( )
60+ const providerName = endpoint . tag ?? endpoint . name
5861 const inputPrice = parseApiPrice ( endpoint . pricing ?. prompt )
5962 const outputPrice = parseApiPrice ( endpoint . pricing ?. completion )
63+ const cacheReadsPrice = parseApiPrice ( endpoint . pricing ?. input_cache_read )
64+ const cacheWritesPrice = parseApiPrice ( endpoint . pricing ?. input_cache_write )
6065
6166 const modelInfo : OpenRouterModelProvider = {
6267 maxTokens : endpoint . max_completion_tokens || endpoint . context_length ,
6368 contextWindow : endpoint . context_length ,
6469 supportsImages : architecture ?. modality ?. includes ( "image" ) ,
65- supportsPromptCache : false ,
70+ supportsPromptCache : typeof cacheReadsPrice !== "undefined" ,
71+ cacheReadsPrice,
72+ cacheWritesPrice,
6673 inputPrice,
6774 outputPrice,
6875 description,
6976 label : providerName ,
7077 }
7178
72- // TODO: This is wrong. We need to fetch the model info from
73- // OpenRouter instead of hardcoding it here. The endpoints payload
74- // doesn't include this unfortunately, so we need to get it from the
75- // main models endpoint.
76- switch ( true ) {
77- case modelId . startsWith ( "anthropic/claude-3.7-sonnet" ) :
78- modelInfo . supportsComputerUse = true
79- modelInfo . supportsPromptCache = true
80- modelInfo . cacheWritesPrice = 3.75
81- modelInfo . cacheReadsPrice = 0.3
82- modelInfo . maxTokens = id === "anthropic/claude-3.7-sonnet:thinking" ? 64_000 : 8192
83- break
84- case modelId . startsWith ( "anthropic/claude-3.5-sonnet-20240620" ) :
85- modelInfo . supportsPromptCache = true
86- modelInfo . cacheWritesPrice = 3.75
87- modelInfo . cacheReadsPrice = 0.3
88- modelInfo . maxTokens = 8192
89- break
90- default :
91- modelInfo . supportsPromptCache = true
92- modelInfo . cacheWritesPrice = 0.3
93- modelInfo . cacheReadsPrice = 0.03
94- break
95- }
96-
9779 models [ providerName ] = modelInfo
9880 }
9981 } catch ( error ) {
0 commit comments