fix: route usage API quota fetches through configured proxy (#194)

This commit is contained in:
diegosouzapw
2026-03-03 12:04:59 -03:00
parent f21ba7df64
commit 8dca8fba6b

View File

@@ -1,8 +1,9 @@
import { getProviderConnectionById, updateProviderConnection } from "@/lib/localDb";
import { getProviderConnectionById, updateProviderConnection, resolveProxyForConnection } from "@/lib/localDb";
import { getMachineId } from "@/shared/utils/machine";
import { getUsageForProvider } from "@omniroute/open-sse/services/usage.ts";
import { getExecutor } from "@omniroute/open-sse/executors/index.ts";
import { syncToCloud } from "@/lib/cloudSync";
import { runWithProxyContext } from "@omniroute/open-sse/utils/proxyFetch.ts";
/**
* Sync to cloud if enabled
@@ -139,8 +140,13 @@ export async function GET(request: Request, { params }: { params: Promise<{ conn
);
}
// Fetch usage from provider API
const usage = await getUsageForProvider(connection);
// Resolve proxy for this connection (key → combo → provider → global → direct)
const proxyInfo = await resolveProxyForConnection(connectionId);
// Fetch usage from provider API, wrapped in proxy context
const usage = await runWithProxyContext(proxyInfo?.proxy || null, () =>
getUsageForProvider(connection)
);
return Response.json(usage);
} catch (error) {
console.error("[Usage API] Error fetching usage:", error);