summaryrefslogtreecommitdiffhomepage
path: root/packages/api/src
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-05-20 22:44:42 +0900
committerAdam Malczewski <[email protected]>2026-05-20 22:44:42 +0900
commitba68da660c9a02b90ff2134152abe650f004867e (patch)
tree832dd87a2e211596b3ef5f3f6ed11774ff881fb7 /packages/api/src
parentc0c55ed7c03188f264ff2c27b9982f2d57d092cc (diff)
downloaddispatch-ba68da660c9a02b90ff2134152abe650f004867e.tar.gz
dispatch-ba68da660c9a02b90ff2134152abe650f004867e.zip
feat: key usage shows all keys at once, removes dropdown, multi-account Claude
- /key-usage route now returns all Claude accounts (not just first) - Added ClaudeAccountUsage type for per-account data - Frontend shows all keys stacked in scrollable cards - Each Claude account rendered separately with label + subscription badge - Removed key selector dropdown
Diffstat (limited to 'packages/api/src')
-rw-r--r--packages/api/src/routes/models.ts33
1 files changed, 19 insertions, 14 deletions
diff --git a/packages/api/src/routes/models.ts b/packages/api/src/routes/models.ts
index b79a45d..906ecc4 100644
--- a/packages/api/src/routes/models.ts
+++ b/packages/api/src/routes/models.ts
@@ -258,24 +258,29 @@ modelsRoutes.get("/key-usage", async (c) => {
try {
if (provider === "anthropic") {
const accounts = discoverClaudeAccounts();
- let account: ClaudeAccount | undefined;
- if (key.definition.credentials_file) {
- account = accounts.find((a) => a.source === key.definition.credentials_file);
- }
- if (!account) {
- account = accounts[0];
- }
- if (!account) {
+ if (accounts.length === 0) {
return c.json({ error: "no Claude accounts available" }, 502);
}
- const report = await getAccountUsage(account);
- if (!report) {
- return c.json({ error: "failed to fetch usage data" }, 502);
- }
+ // Fetch usage for all discovered accounts
+ const accountResults = await Promise.all(
+ accounts.map(async (acct) => {
+ const report = await getAccountUsage(acct);
+ return {
+ label: acct.label,
+ source: acct.source,
+ subscriptionType: acct.credentials.subscriptionType,
+ fiveHour: report?.fiveHour,
+ sevenDay: report?.sevenDay,
+ error: report ? undefined : "failed to fetch",
+ };
+ }),
+ );
return c.json({
provider: "anthropic",
- fiveHour: report.fiveHour,
- sevenDay: report.sevenDay,
+ accounts: accountResults,
+ // Legacy single-account fields (first account)
+ fiveHour: accountResults[0]?.fiveHour,
+ sevenDay: accountResults[0]?.sevenDay,
});
} else if (provider === "opencode-go") {
// Cookie-based HTML scraper. Uses OPENCODE_COOKIE env var plus