Skip to content

Commit f21e56a

Browse files
committed
support reasoning for openrouter
1 parent 1a1b881 commit f21e56a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/providers/openrouter/chatComplete.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
generateErrorResponse,
1111
generateInvalidProviderResponseError,
1212
} from '../utils';
13+
import { transformReasoningParams } from './utils';
1314

1415
export const OpenrouterChatCompleteConfig: ProviderConfig = {
1516
model: {
@@ -48,6 +49,15 @@ export const OpenrouterChatCompleteConfig: ProviderConfig = {
4849
},
4950
reasoning: {
5051
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+
},
5161
},
5262
top_p: {
5363
param: 'top_p',
@@ -77,6 +87,17 @@ export const OpenrouterChatCompleteConfig: ProviderConfig = {
7787
param: 'stream',
7888
default: false,
7989
},
90+
stream_options: {
91+
param: 'usage',
92+
transform: (params: Params) => {
93+
if (params.stream_options?.include_usage) {
94+
return {
95+
include: params.stream_options?.include_usage,
96+
};
97+
}
98+
return null;
99+
},
100+
},
80101
response_format: {
81102
param: 'response_format',
82103
},

src/providers/openrouter/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Params } from '../../types/requestBody';
2+
3+
interface OpenRouterParams extends Params {
4+
reasoning?: OpenrouterReasoningParam;
5+
}
6+
7+
type OpenrouterReasoningParam = {
8+
effort?: 'low' | 'medium' | 'high' | string;
9+
max_tokens?: number;
10+
exclude?: boolean;
11+
};
12+
13+
export const transformReasoningParams = (params: OpenRouterParams) => {
14+
let reasoning: OpenrouterReasoningParam = { ...params.reasoning };
15+
if (params.reasoning_effort) {
16+
reasoning.effort = params.reasoning_effort;
17+
}
18+
return Object.keys(reasoning).length > 0 ? reasoning : null;
19+
};

0 commit comments

Comments
 (0)