File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import {
10
10
generateErrorResponse ,
11
11
generateInvalidProviderResponseError ,
12
12
} from '../utils' ;
13
- import { transformReasoningParams } from './utils' ;
13
+ import { transformReasoningParams , transformUsageOptions } from './utils' ;
14
14
15
15
export const OpenrouterChatCompleteConfig : ProviderConfig = {
16
16
model : {
@@ -82,6 +82,9 @@ export const OpenrouterChatCompleteConfig: ProviderConfig = {
82
82
} ,
83
83
usage : {
84
84
param : 'usage' ,
85
+ transform : ( params : Params ) => {
86
+ return transformUsageOptions ( params ) ;
87
+ } ,
85
88
} ,
86
89
stream : {
87
90
param : 'stream' ,
@@ -90,12 +93,7 @@ export const OpenrouterChatCompleteConfig: ProviderConfig = {
90
93
stream_options : {
91
94
param : 'usage' ,
92
95
transform : ( params : Params ) => {
93
- if ( params . stream_options ?. include_usage ) {
94
- return {
95
- include : params . stream_options ?. include_usage ,
96
- } ;
97
- }
98
- return null ;
96
+ return transformUsageOptions ( params ) ;
99
97
} ,
100
98
} ,
101
99
response_format : {
Original file line number Diff line number Diff line change 1
1
import { Params } from '../../types/requestBody' ;
2
2
3
+ interface OpenrouterUsageParam {
4
+ include ?: boolean ;
5
+ }
6
+
3
7
interface OpenRouterParams extends Params {
4
8
reasoning ?: OpenrouterReasoningParam ;
5
9
}
@@ -17,3 +21,11 @@ export const transformReasoningParams = (params: OpenRouterParams) => {
17
21
}
18
22
return Object . keys ( reasoning ) . length > 0 ? reasoning : null ;
19
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