@wopr-network/platform-core 1.36.1 → 1.36.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gateway/proxy.js +20 -1
- package/package.json +1 -1
- package/src/gateway/proxy.ts +20 -1
package/dist/gateway/proxy.js
CHANGED
|
@@ -261,7 +261,26 @@ export function chatCompletions(deps) {
|
|
|
261
261
|
});
|
|
262
262
|
debitCredits(deps, tenant.id, cost, deps.defaultMargin, "chat-completions", "openrouter");
|
|
263
263
|
}
|
|
264
|
-
|
|
264
|
+
// Sanitize response: strip non-standard OpenRouter fields from usage
|
|
265
|
+
// (cost, cost_details, is_byok, prompt_tokens_details, completion_tokens_details)
|
|
266
|
+
// that break downstream AI SDKs expecting standard OpenAI format.
|
|
267
|
+
let sanitizedBody = responseBody;
|
|
268
|
+
try {
|
|
269
|
+
const parsed = JSON.parse(responseBody);
|
|
270
|
+
if (parsed.usage && typeof parsed.usage === "object") {
|
|
271
|
+
const u = parsed.usage;
|
|
272
|
+
parsed.usage = {
|
|
273
|
+
prompt_tokens: u.prompt_tokens,
|
|
274
|
+
completion_tokens: u.completion_tokens,
|
|
275
|
+
total_tokens: u.total_tokens,
|
|
276
|
+
};
|
|
277
|
+
sanitizedBody = JSON.stringify(parsed);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
// Forward raw body if parse fails
|
|
282
|
+
}
|
|
283
|
+
return new Response(sanitizedBody, {
|
|
265
284
|
status: res.status,
|
|
266
285
|
headers: { "Content-Type": "application/json" },
|
|
267
286
|
});
|
package/package.json
CHANGED
package/src/gateway/proxy.ts
CHANGED
|
@@ -350,7 +350,26 @@ export function chatCompletions(deps: ProxyDeps) {
|
|
|
350
350
|
debitCredits(deps, tenant.id, cost, deps.defaultMargin, "chat-completions", "openrouter");
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
-
|
|
353
|
+
// Sanitize response: strip non-standard OpenRouter fields from usage
|
|
354
|
+
// (cost, cost_details, is_byok, prompt_tokens_details, completion_tokens_details)
|
|
355
|
+
// that break downstream AI SDKs expecting standard OpenAI format.
|
|
356
|
+
let sanitizedBody = responseBody;
|
|
357
|
+
try {
|
|
358
|
+
const parsed = JSON.parse(responseBody) as Record<string, unknown>;
|
|
359
|
+
if (parsed.usage && typeof parsed.usage === "object") {
|
|
360
|
+
const u = parsed.usage as Record<string, unknown>;
|
|
361
|
+
parsed.usage = {
|
|
362
|
+
prompt_tokens: u.prompt_tokens,
|
|
363
|
+
completion_tokens: u.completion_tokens,
|
|
364
|
+
total_tokens: u.total_tokens,
|
|
365
|
+
};
|
|
366
|
+
sanitizedBody = JSON.stringify(parsed);
|
|
367
|
+
}
|
|
368
|
+
} catch {
|
|
369
|
+
// Forward raw body if parse fails
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return new Response(sanitizedBody, {
|
|
354
373
|
status: res.status,
|
|
355
374
|
headers: { "Content-Type": "application/json" },
|
|
356
375
|
});
|