File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
10
10
generateErrorResponse ,
11
11
generateInvalidProviderResponseError ,
12
12
} from '../utils' ;
13
+ import { transformReasoningParams , transformUsageOptions } from './utils' ;
13
14
14
15
export const OpenrouterChatCompleteConfig : ProviderConfig = {
15
16
model : {
@@ -48,6 +49,15 @@ export const OpenrouterChatCompleteConfig: ProviderConfig = {
48
49
} ,
49
50
reasoning : {
50
51
param : 'reasoning' ,
52
+ transform : ( params : Params ) => {
53
+ return transformReasoningParams ( params ) ;
54
+ } ,
55
+ } ,
56
+ reasoning_effort : {
57
+ param : 'reasoning' ,
58
+ transform : ( params : Params ) => {
59
+ return transformReasoningParams ( params ) ;
60
+ } ,
51
61
} ,
52
62
top_p : {
53
63
param : 'top_p' ,
@@ -72,11 +82,20 @@ export const OpenrouterChatCompleteConfig: ProviderConfig = {
72
82
} ,
73
83
usage : {
74
84
param : 'usage' ,
85
+ transform : ( params : Params ) => {
86
+ return transformUsageOptions ( params ) ;
87
+ } ,
75
88
} ,
76
89
stream : {
77
90
param : 'stream' ,
78
91
default : false ,
79
92
} ,
93
+ stream_options : {
94
+ param : 'usage' ,
95
+ transform : ( params : Params ) => {
96
+ return transformUsageOptions ( params ) ;
97
+ } ,
98
+ } ,
80
99
response_format : {
81
100
param : 'response_format' ,
82
101
} ,
Original file line number Diff line number Diff line change
1
+ import { Params } from '../../types/requestBody' ;
2
+
3
+ interface OpenrouterUsageParam {
4
+ include ?: boolean ;
5
+ }
6
+
7
+ interface OpenRouterParams extends Params {
8
+ reasoning ?: OpenrouterReasoningParam ;
9
+ }
10
+
11
+ type OpenrouterReasoningParam = {
12
+ effort ?: 'low' | 'medium' | 'high' | string ;
13
+ max_tokens ?: number ;
14
+ exclude ?: boolean ;
15
+ } ;
16
+
17
+ export const transformReasoningParams = ( params : OpenRouterParams ) => {
18
+ let reasoning : OpenrouterReasoningParam = { ...params . reasoning } ;
19
+ if ( params . reasoning_effort ) {
20
+ reasoning . effort = params . reasoning_effort ;
21
+ }
22
+ return Object . keys ( reasoning ) . length > 0 ? reasoning : null ;
23
+ } ;
24
+
25
+ export const transformUsageOptions = ( params : OpenRouterParams ) => {
26
+ let usage : OpenrouterUsageParam = { ...params . usage } ;
27
+ if ( params . stream_options ?. include_usage ) {
28
+ usage . include = params . stream_options ?. include_usage ;
29
+ }
30
+ return Object . keys ( usage ) . length > 0 ? usage : null ;
31
+ } ;
You can’t perform that action at this time.
0 commit comments