Skip to content

Commit aa19b2c

Browse files
feat: add provider routing support (#143)
- Add provider routing types for order, sort, quantizations, etc. - Support all provider routing parameters from OpenRouter API - Enable request routing control via provider preferences Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 7ca635e commit aa19b2c

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/chat/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ export class OpenRouterChatLanguageModel implements LanguageModelV2 {
131131
reasoning: this.settings.reasoning,
132132
usage: this.settings.usage,
133133

134+
// Provider routing settings:
135+
provider: this.settings.provider,
136+
134137
// extra body:
135138
...this.config.extraBody,
136139
...this.settings.extraBody,

src/types/openrouter-chat-settings.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,52 @@ A unique identifier representing your end-user, which can help OpenRouter to
4343
monitor and detect abuse. Learn more.
4444
*/
4545
user?: string;
46+
47+
/**
48+
* Provider routing preferences to control request routing behavior
49+
*/
50+
provider?: {
51+
/**
52+
* List of provider slugs to try in order (e.g. ["anthropic", "openai"])
53+
*/
54+
order?: string[];
55+
/**
56+
* Whether to allow backup providers when primary is unavailable (default: true)
57+
*/
58+
allow_fallbacks?: boolean;
59+
/**
60+
* Only use providers that support all parameters in your request (default: false)
61+
*/
62+
require_parameters?: boolean;
63+
/**
64+
* Control whether to use providers that may store data
65+
*/
66+
data_collection?: 'allow' | 'deny';
67+
/**
68+
* List of provider slugs to allow for this request
69+
*/
70+
only?: string[];
71+
/**
72+
* List of provider slugs to skip for this request
73+
*/
74+
ignore?: string[];
75+
/**
76+
* List of quantization levels to filter by (e.g. ["int4", "int8"])
77+
*/
78+
quantizations?: Array<'int4' | 'int8' | 'fp4' | 'fp6' | 'fp8' | 'fp16' | 'bf16' | 'fp32' | 'unknown'>;
79+
/**
80+
* Sort providers by price, throughput, or latency
81+
*/
82+
sort?: 'price' | 'throughput' | 'latency';
83+
/**
84+
* Maximum pricing you want to pay for this request
85+
*/
86+
max_price?: {
87+
prompt?: number | string;
88+
completion?: number | string;
89+
image?: number | string;
90+
audio?: number | string;
91+
request?: number | string;
92+
};
93+
};
4694
} & OpenRouterSharedSettings;

0 commit comments

Comments
 (0)