From df90877d958872c1e19c8e9ec1e859dc35dd8cfb Mon Sep 17 00:00:00 2001 From: Sarah Wooders Date: Wed, 28 Jan 2026 21:39:33 -0800 Subject: [PATCH] Fix: Always use Letta Cloud for billing check, not .env LETTA_BASE_URL --- src/onboard.ts | 8 +------- src/utils/model-selection.ts | 17 +++++++++-------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/onboard.ts b/src/onboard.ts index ed66b1a..861a79a 100644 --- a/src/onboard.ts +++ b/src/onboard.ts @@ -373,14 +373,8 @@ async function stepModel(config: OnboardConfig, env: Record): 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'}`); } diff --git a/src/utils/model-selection.ts b/src/utils/model-selection.ts index 3c257eb..3a72330 100644 --- a/src/utils/model-selection.ts +++ b/src/utils/model-selection.ts @@ -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 { +export async function getBillingTier(apiKey?: string, isSelfHosted?: boolean): Promise { 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}`, }, });