11import { defineCommand } from '../../command' ;
22import { requestJson } from '../../client/http' ;
3- import { quotaEndpoint , usageEndpoint } from '../../client/endpoints' ;
3+ import { selectUsageEndpoint } from '../../client/endpoints' ;
4+ import { resolveCredential } from '../../auth/resolver' ;
45import { formatOutput , detectOutputFormat } from '../../output/formatter' ;
56import { renderUsage } from '../../output/usage' ;
67import type { Config } from '../../config/schema' ;
78import type { GlobalFlags } from '../../types/flags' ;
8- import type { AccountBalanceResponse , QuotaModelRemain } from '../../types/api' ;
9-
10- interface QuotaApiResponse {
11- model_remains : QuotaModelRemain [ ] ;
12- }
9+ import type { AccountBalanceResponse , QuotaResponse } from '../../types/api' ;
1310
1411export default defineCommand ( {
1512 name : 'quota show' ,
@@ -26,21 +23,20 @@ export default defineCommand({
2623 }
2724
2825 const format = detectOutputFormat ( flags . output as string | undefined ) ;
29- const apiKey = config . apiKey || config . fileApiKey ;
26+ const credential = await resolveCredential ( config ) ;
27+ const endpoint = selectUsageEndpoint ( config . baseUrl , credential ) ;
3028
31- if ( apiKey && apiKey . startsWith ( 'sk-api-' ) ) {
32- const url = usageEndpoint ( config . baseUrl , apiKey ) ;
33- const response = await requestJson < AccountBalanceResponse > ( config , { url } ) ;
29+ if ( endpoint . kind === 'account-balance' ) {
30+ const response = await requestJson < AccountBalanceResponse > ( config , { url : endpoint . url } ) ;
3431 if ( format !== 'text' ) {
3532 console . log ( formatOutput ( response , format ) ) ;
3633 return ;
3734 }
38- renderUsage ( response , config , apiKey ) ;
35+ renderUsage ( response , config , credential . token ) ;
3936 return ;
4037 }
4138
42- const url = quotaEndpoint ( config . baseUrl ) ;
43- const response = await requestJson < QuotaApiResponse > ( config , { url } ) ;
39+ const response = await requestJson < QuotaResponse > ( config , { url : endpoint . url } ) ;
4440 const models = response . model_remains || [ ] ;
4541
4642 if ( format !== 'text' ) {
0 commit comments