Find Kimi usage for logins to kimi.ai

The Kimi CLI keeps one credential slot per deployment. A login to the
global (kimi.ai) deployment writes its token to
credentials/kimi-code-env-<hash>.json and talks to api.kimi.ai, but the
usage source only read credentials/kimi-code.json and only called
api.kimi.com. Users signed in through kimi.ai saw no Kimi usage, or a
"Login expired. Sign in again." message when an old kimi-code.json from
an earlier login was still on disk.

Discovery now checks the slots of both official deployments and picks
the one with the latest expiry, which is the slot the CLI keeps
refreshing. The usage request goes to the API of that deployment.

Kimi access tokens last 15 minutes, so a CLI token is often expired
while the user is still signed in. Report those with refreshedBy so the
Usage page says to run kimi instead of asking for a new sign-in.
This commit is contained in:
benthecarman
2026-11-01 01:03:14 -06:00
parent 14519bdb5b
commit 521afd9f33
3 changed files with 105 additions and 22 deletions
@@ -3,6 +3,7 @@ export const inputSchema = z
.object({
store: z.enum(["env", "file"]),
locator: z.string().min(1),
baseUrl: z.url().optional(),
})
.strict();
export type UsageInput = z.infer<typeof inputSchema>;