Simple examples showing how to use the @merit-systems/echo-typescript-sdk in your projects.
npm install @merit-systems/echo-typescript-sdkimport { EchoClient } from '@merit-systems/echo-typescript-sdk';
const echo = new EchoClient({
apiKey: 'your-api-key-here',
baseUrl: 'https://echo.merit.systems',
});const balance = await echo.getBalance();
console.log(`You have $${balance.balance} remaining`);const apps = await echo.listEchoApps();
console.log(`You have ${apps.length} apps`);
apps.forEach(app => {
console.log(`- ${app.name} (${app.isActive ? 'Active' : 'Inactive'})`);
});const app = await echo.getEchoApp('your-app-id');
console.log(`App: ${app.name}`);
console.log(`URL: ${echo.getAppUrl(app.id)}`);const payment = await echo.createPaymentLink({
amount: 10,
description: 'Buy $10 credits',
});
console.log(`Pay here: ${payment.paymentLink.url}`);const user = await echo.getUserInfo();
console.log(`Hello ${user.name}!`);
console.log(`Email: ${user.email}`);const models = await echo.listSupportedModels();
console.log(`${models.length} models available`);
// Find OpenAI models
const openAIModels = models.filter(m => m.provider === 'openai');
console.log(
'OpenAI models:',
openAIModels.map(m => m.name)
);async function getDashboard() {
const [balance, apps, user] = await Promise.all([
echo.getBalance(),
echo.listEchoApps(),
echo.getUserInfo(),
]);
return { balance, apps, user };
}
const dashboard = await getDashboard();
console.log(dashboard);const models = await echo.listSupportedModels();
const cheapest = models.sort(
(a, b) => a.pricing.input_cost_per_token - b.pricing.input_cost_per_token
)[0];
console.log(`Cheapest model: ${cheapest.name}`);
console.log(`Cost: $${cheapest.pricing.input_cost_per_token} per input token`);const app = await echo.getEchoApp('your-app-id');
console.log(`${app.name} has used ${app.totalTokens || 0} tokens`);
console.log(`Total cost: $${app.totalCost || 0}`);Create a .env file:
ECHO_API_KEY=your_api_key_here
ECHO_BASE_URL=https://echo.merit.systemsThen use without configuration:
const echo = new EchoClient(); // Uses environment variablesImport types for better development experience:
import {
EchoClient,
EchoApp,
Balance,
User,
} from '@merit-systems/echo-typescript-sdk';
const echo = new EchoClient({ apiKey: 'your-key' });
const balance: Balance = await echo.getBalance();
const apps: EchoApp[] = await echo.listEchoApps();
const user: User = await echo.getUserInfo();That's it! These examples cover the most common use cases.