TypeScript SDK
Client
EchoClient setup, configuration, and environment management
Client
The EchoClient
is your gateway to the Echo platform, providing access to all platform resources and operations.
Basic Setup
import { EchoClient } from '@merit-systems/echo-typescript-sdk';
const echo = new EchoClient({
apiKey: 'your-api-key'
});
Configuration Options
import type { EchoClientOptions } from '@merit-systems/echo-typescript-sdk';
EchoClientOptions
Prop | Type | Default |
---|---|---|
tokenProvider? | TokenProvider | - |
baseUrl? | string | - |
apiKey? | string | - |
Environment Configuration
Using Environment Variables
// Automatically uses ECHO_API_KEY and ECHO_BASE_URL if available
const echo = new EchoClient();
// Or explicitly set via environment
process.env.ECHO_API_KEY = 'your-api-key';
process.env.ECHO_BASE_URL = 'https://echo.merit.systems';
Configuration Precedence
- Explicit options - Passed directly to constructor
- Environment variables -
ECHO_API_KEY
,ECHO_BASE_URL
- Defaults -
https://echo.merit.systems
Resource Access
The client provides access to all platform resources:
const echo = new EchoClient({ apiKey: 'your-key' });
// Resource modules
echo.apps // App management
echo.balance // Account balance
echo.payments // Payment operations
echo.models // Supported models
echo.users // User information
Error Handling
import { EchoError } from '@merit-systems/echo-typescript-sdk';
try {
const balance = await echo.balance.getBalance();
} catch (error) {
if (error instanceof EchoError) {
console.log('Echo API Error:', error.code, error.message);
} else {
console.log('Network Error:', error);
}
}
Advanced Configuration
Custom Base URL
const echo = new EchoClient({
apiKey: 'your-key',
baseUrl: 'https://custom-echo-instance.com'
});
With Token Provider
import { ApiKeyTokenProvider } from '@merit-systems/echo-typescript-sdk';
const tokenProvider = new ApiKeyTokenProvider('your-api-key');
const echo = new EchoClient({
tokenProvider
});
For OAuth and advanced authentication patterns, see the Authentication section.