Add debug logging for API key and billing tier

This commit is contained in:
Sarah Wooders
2026-01-28 21:38:23 -08:00
parent c7f8be5d7e
commit 691df41ff7
2 changed files with 14 additions and 6 deletions

View File

@@ -373,8 +373,14 @@ async function stepModel(config: OnboardConfig, env: Record<string, string>): Pr
if (!isSelfHosted) {
spinner.start('Checking account...');
// Pass the API key explicitly since it may not be in process.env yet
// Priority: manually entered key > env object > process.env
const apiKey = config.apiKey || env.LETTA_API_KEY || process.env.LETTA_API_KEY;
console.log(`[Debug] config.apiKey: ${config.apiKey?.slice(0, 20)}...`);
console.log(`[Debug] env.LETTA_API_KEY: ${env.LETTA_API_KEY?.slice(0, 20)}...`);
console.log(`[Debug] process.env.LETTA_API_KEY: ${process.env.LETTA_API_KEY?.slice(0, 20)}...`);
console.log(`[Debug] Using apiKey: ${apiKey?.slice(0, 20)}...`);
billingTier = await getBillingTier(apiKey);
console.log(`[Debug] billingTier result: "${billingTier}"`);
config.billingTier = billingTier ?? undefined;
spinner.stop(billingTier === 'free' ? 'Free plan' : `Plan: ${billingTier || 'unknown'}`);
}

View File

@@ -35,23 +35,25 @@ export async function getBillingTier(apiKey?: string): Promise<string | null> {
return null;
}
if (!key) return 'free';
if (!key) {
return 'free';
}
const response = await fetch(`${baseUrl}/v1/metadata/balance`, {
headers: { 'Authorization': `Bearer ${key}` },
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${key}`,
},
});
if (!response.ok) {
console.error(`[BillingTier] API returned ${response.status}`);
return 'free';
}
const data = await response.json() as { billing_tier?: string };
const tier = data.billing_tier?.toLowerCase() ?? 'free';
console.log(`[BillingTier] Got tier: ${tier}`);
return tier;
} catch (err) {
console.error(`[BillingTier] Error:`, err);
} catch {
return 'free';
}
}