Echo
Getting Started

TypeScript CLI

Build AI CLI apps with Echo's billing infrastructure

TypeScript CLI with Echo

Create CLI tools that generate revenue from AI usage. Echo handles user authentication, billing, and AI provider access through a simple API key flow.

Install SDKs

npm i @merit-systems/echo-typescript-sdk ai enquirer open
yarn add @merit-systems/echo-typescript-sdk ai enquirer open
pnpm add @merit-systems/echo-typescript-sdk ai enquirer open
bun add @merit-systems/echo-typescript-sdk ai enquirer open

Create Echo App

Go to echo.merit.systems/new to get your app_id.

Set up authentication

cli.ts
import { EchoClient, createEchoOpenAI } from '@merit-systems/echo-typescript-sdk';
import { generateText } from 'ai';
import { prompt } from 'enquirer';
import { open } from 'open';

const APP_ID = 'your-echo-app-id';

// Get API key from user
console.log('Opening Echo to create your API key...');
await open(`https://echo.merit.systems/app/${APP_ID}/keys`);

const { apiKey } = await prompt({
  type: 'input',
  name: 'apiKey',
  message: 'Enter your API key:'
});

Create AI provider

cli.ts
// Create Echo client for balance/payments
const echo = new EchoClient({ apiKey });

// Create OpenAI provider with Echo billing
const openai = createEchoOpenAI(
  { appId: APP_ID },
  async () => apiKey
);

Make AI calls

cli.ts
// Generate text with automatic billing
const { text } = await generateText({
  model: openai('gpt-4'),
  prompt: 'Explain quantum computing in simple terms',
});

console.log(text);

Add balance checking

cli.ts
// Check user's balance
const balance = await echo.balance.getBalance();
console.log(`Balance: $${balance.balance}`);

// Create top-up link if needed
if (balance.balance < 1) {
  const payment = await echo.payments.createPaymentLink({
    amount: 10,
  });

  console.log('Low balance. Opening payment link...');
  await open(payment.url);
}

Run your CLI

npx tsx cli.ts

Next Steps

For detailed documentation and advanced features, see the TypeScript SDK overview.