Fix: Always use Letta Cloud for billing check, not .env LETTA_BASE_URL

This commit is contained in:
Sarah Wooders
2026-01-28 21:39:33 -08:00
parent 691df41ff7
commit df90877d95
2 changed files with 10 additions and 15 deletions

View File

@@ -373,14 +373,8 @@ 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}"`);
billingTier = await getBillingTier(apiKey, isSelfHosted);
config.billingTier = billingTier ?? undefined;
spinner.stop(billingTier === 'free' ? 'Free plan' : `Plan: ${billingTier || 'unknown'}`);
}

View File

@@ -24,25 +24,26 @@ export interface ModelInfo {
/**
* Get billing tier from Letta API
* Uses /v1/metadata/balance endpoint (same as letta-code)
*
* @param apiKey - The API key to use
* @param isSelfHosted - If true, skip billing check (self-hosted has no tiers)
*/
export async function getBillingTier(apiKey?: string): Promise<string | null> {
export async function getBillingTier(apiKey?: string, isSelfHosted?: boolean): Promise<string | null> {
try {
const baseUrl = process.env.LETTA_BASE_URL || 'https://api.letta.com';
const key = apiKey || process.env.LETTA_API_KEY;
// Self-hosted servers don't have billing tiers
if (baseUrl !== 'https://api.letta.com') {
if (isSelfHosted) {
return null;
}
if (!key) {
if (!apiKey) {
return 'free';
}
const response = await fetch(`${baseUrl}/v1/metadata/balance`, {
// Always use Letta Cloud for billing check (not process.env.LETTA_BASE_URL)
const response = await fetch('https://api.letta.com/v1/metadata/balance', {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${key}`,
'Authorization': `Bearer ${apiKey}`,
},
});