From 8b923a8d817e86c82c0e690210bacb0240999017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Zucchinetti?= Date: Mon, 9 Nov 2026 22:43:23 +0100 Subject: [PATCH] Fix OpenRouter FX lookups and the Vercel charges end date OpenRouter's activity API dates each row as "2026-11-08 00:00:00". The connector passed that through as the line date, so the sync asked Frankfurter for /v1/2026-11-08 00:00:00, got a 404, and the connection errored for any workspace not in USD. Lines now carry the day alone; externalIds are unchanged, so stored lines are updated, not duplicated. Vercel's billing charges request ended at midnight after today, a moment in the future, and the connection failed with a 400. The end is now capped at the start of the current UTC day; today's charges come with the next sync, which rereads the last 3 days. --- src/connectors/openrouter.ts | 5 +++-- src/connectors/vercel.ts | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/connectors/openrouter.ts b/src/connectors/openrouter.ts index f2a2315..b0e34cb 100644 --- a/src/connectors/openrouter.ts +++ b/src/connectors/openrouter.ts @@ -4,6 +4,7 @@ import { type CostLine, type Credentials, getJson, toCents } from "./types"; const BASE = "https://openrouter.ai/api/v1"; const headers = (c: Credentials) => ({ Authorization: `Bearer ${c.key}` }); +// `date` comes as "2026-11-08 00:00:00"; a line keeps the day alone. type Row = { date: string; model: string; usage: number }; type Key = { hash: string; @@ -44,7 +45,7 @@ export function activityLines( if (!cents) continue; out.push({ externalId: `${k}:${key.hash}`, - date: r.date, + date: r.date.slice(0, 10), currency: "USD", amountCents: cents, service: r.model, @@ -58,7 +59,7 @@ export function activityLines( if (cents <= 0) continue; out.push({ externalId: `${k}:none`, - date: r.date, + date: r.date.slice(0, 10), currency: "USD", amountCents: cents, service: r.model, diff --git a/src/connectors/vercel.ts b/src/connectors/vercel.ts index 717487e..34c8b7c 100644 --- a/src/connectors/vercel.ts +++ b/src/connectors/vercel.ts @@ -72,7 +72,13 @@ export const vercel = register({ // https://vercel.com/docs/rest-api/reference/endpoints/billing/list-focus-billing-charges async fetchCosts(c, range: SyncRange) { const team = await teamId(c); - const end = Date.parse(`${range.to}T00:00:00Z`) + DAY; + // `to` is exclusive and day-granular. Stop at the start of the current + // UTC day rather than past it: today's partial day comes with the next + // sync, which rereads the last 3 days. + const end = Math.min( + Date.parse(`${range.to}T00:00:00Z`) + DAY, + Math.floor(Date.now() / DAY) * DAY, + ); let text = ""; for ( let start = Date.parse(`${range.from}T00:00:00Z`);