Skip to content

Commit 11f97ee

Browse files
committed
fix: route usage API quota fetches through configured proxy (#194)
1 parent de41f4a commit 11f97ee

File tree

1 file changed

+9
-3
lines changed
  • src/app/api/usage/[connectionId]

1 file changed

+9
-3
lines changed

src/app/api/usage/[connectionId]/route.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { getProviderConnectionById, updateProviderConnection } from "@/lib/localDb";
1+
import { getProviderConnectionById, updateProviderConnection, resolveProxyForConnection } from "@/lib/localDb";
22
import { getMachineId } from "@/shared/utils/machine";
33
import { getUsageForProvider } from "@omniroute/open-sse/services/usage.ts";
44
import { getExecutor } from "@omniroute/open-sse/executors/index.ts";
55
import { syncToCloud } from "@/lib/cloudSync";
6+
import { runWithProxyContext } from "@omniroute/open-sse/utils/proxyFetch.ts";
67

78
/**
89
* Sync to cloud if enabled
@@ -139,8 +140,13 @@ export async function GET(request: Request, { params }: { params: Promise<{ conn
139140
);
140141
}
141142

142-
// Fetch usage from provider API
143-
const usage = await getUsageForProvider(connection);
143+
// Resolve proxy for this connection (key → combo → provider → global → direct)
144+
const proxyInfo = await resolveProxyForConnection(connectionId);
145+
146+
// Fetch usage from provider API, wrapped in proxy context
147+
const usage = await runWithProxyContext(proxyInfo?.proxy || null, () =>
148+
getUsageForProvider(connection)
149+
);
144150
return Response.json(usage);
145151
} catch (error) {
146152
console.error("[Usage API] Error fetching usage:", error);

0 commit comments

Comments
 (0)