Skip to content

Commit e02e178

Browse files
committed
fix(gateway): treat :free suffix models as zero-cost for budget throttle
OpenRouter models with ':free' suffix (e.g. nvidia/nemotron-3-ultra-550b-a55b:free) were falling through to unknown-model defaults ($3/M input, $15/M output), causing the daily budget throttle to penalize free model usage. Now detected at both the pricing layer (getPricingSync) and fallback entry layer (fallbackEntry) and assigned $0 pricing.
1 parent 04a8eb1 commit e02e178

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎packages/core/src/fetch-interceptor.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ export function installFetchInterceptor(
128128
// any prefix) is passed via X-Lore-Upstream-URL.
129129
const upstream = new URL(url);
130130
const gateway = new URL(config.gatewayBase);
131-
const v1Match = upstream.pathname.match(/(\/v1\/.*)$/);
132-
const apiPath = v1Match?.[1] ?? upstream.pathname;
131+
const v1Idx = upstream.pathname.lastIndexOf("/v1/");
132+
const apiPath =
133+
v1Idx >= 0 ? upstream.pathname.slice(v1Idx) : upstream.pathname;
133134
const gatewayUrl = `${gateway.origin}${apiPath}${upstream.search}`;
134135

135136
// Merge original headers + X-Lore-* headers.
@@ -145,10 +146,10 @@ export function installFetchInterceptor(
145146

146147
// Pass the original upstream base URL (everything before /v1/...).
147148
// The gateway uses this as the highest-priority routing signal.
148-
const upstreamBase = v1Match
149-
? upstream.origin +
150-
upstream.pathname.slice(0, upstream.pathname.length - v1Match[1].length)
151-
: upstream.origin;
149+
const upstreamBase =
150+
v1Idx >= 0
151+
? upstream.origin + upstream.pathname.slice(0, v1Idx)
152+
: upstream.origin;
152153
headers.set("x-lore-upstream-url", upstreamBase);
153154

154155
// Inject dynamic context headers (session ID, project, git remote, etc.)

‎packages/gateway/src/cost-tracker.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,10 @@ type Pricing = {
571571
* Falls back to sensible defaults (same logic as sentry.ts getPricing).
572572
*/
573573
export function getPricingSync(model: string): Pricing {
574+
// OpenRouter `:free` suffix models cost nothing — don't inflate budget.
575+
if (model.endsWith(":free")) {
576+
return { input: 0, output: 0, cache_read: 0, cache_write: 0 };
577+
}
574578
const entry = getModelEntrySync(model);
575579
const input = entry.cost?.input ?? 3;
576580
return {

‎packages/gateway/src/worker-model.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ const FALLBACK_PRICING: Array<{
125125
];
126126

127127
function fallbackEntry(modelID: string): ModelsDevEntry {
128+
// OpenRouter `:free` suffix models cost nothing — don't inflate budget.
129+
if (modelID.endsWith(":free")) {
130+
return {
131+
id: modelID,
132+
cost: { input: 0, output: 0, cache_read: 0, cache_write: 0 },
133+
limit: { context: 200_000, output: 8_192 },
134+
};
135+
}
136+
128137
for (const fb of FALLBACK_PRICING) {
129138
if (modelID.startsWith(fb.prefix)) {
130139
return {

0 commit comments

Comments
 (0)