SDK & Tools
TypeScript SDK
The official TypeScript/JavaScript SDK for apitree. One import, the entire apitree catalog.
Installation
bashnpm
npm install @apitreedev/sdkBasic Usage
tsApitreeClient
import { ApitreeClient } from '@apitreedev/sdk'; const apitree = new ApitreeClient('nxs_live_YOUR_KEY'); // Call any API const result = await apitree.call('exchange-rates'); console.log(result.data); console.log(result.meta.latency_ms);
Batch Calls
tsapitree.batch()
// Call up to 10 APIs concurrently const batch = await apitree.batch([ { api: 'exchange-rates' }, { api: 'usgs-earthquake', path: 'query', params: { format: 'geojson', limit: 1 } }, { api: 'open-meteo-forecast', params: { latitude: 37.5, longitude: 127, current: 'temperature_2m' } }, ]); batch.results.forEach(r => console.log(r));
Other Methods
tsClient methods
// Search APIs const apis = await apitree.search('weather data'); // Get API details const details = await apitree.getApi('exchange-rates'); // Check usage const usage = await apitree.getUsage(); // Export usage logs const csv = await apitree.exportUsage({ format: 'csv', days: 7 }); // Get credit balance const credits = await apitree.getCredits();
Error Handling
tsApitreeError
import { ApitreeClient, ApitreeError } from '@apitreedev/sdk'; try { const result = await apitree.call('some-api'); } catch (err) { if (err instanceof ApitreeError) { console.log(err.status); // 429, 402, 502, etc console.log(err.message); } }