TypeScript SDK — @cryptoai/gateway
ESM-only, Node 20+. Uses native fetch + ReadableStream + crypto.randomUUID(). Currently at version 0.2.0.
Install
npm install @cryptoai/gateway
# Optional peer-deps for OpenTelemetry tracing
npm install @opentelemetry/api @opentelemetry/sdk-trace-node \
@opentelemetry/exporter-trace-otlp-httpQuickstart
import { CryptoAIClient } from '@cryptoai/gateway';
const client = new CryptoAIClient({
apiKey: process.env.CRYPTOAI_API_KEY ?? null,
baseUrl: 'https://api.cryptoai.gateway',
});
const quote = await client.swap.quote({
tokenIn: 'USDC',
tokenOut: 'ETH',
amount: '1000',
chain: 'ethereum',
});
console.log(quote.amountOut, quote.feeUsd);Endpoint accessors
client.swap— quote, execute, get, uxStateclient.strategies— create, list, pause, resume, stop, getclient.ai— chat (returnsAsyncGenerator<ChatChunk>), streamChatclient.billing— plans, usageclient.risk·client.legal·client.dsar·client.onboardingclient.public·client.health
Error handling
Exception hierarchy mirrors Python — CryptoAIError → CryptoAIClientError / CryptoAIServerError / CryptoAITransportError. Domain logic branches on err.code. 429/503 retries honor Retry-After automatically.
Opt-in telemetry (M5-S2)
import { CryptoAIClient, configureConsoleExporter } from '@cryptoai/gateway';
configureConsoleExporter();
const client = new CryptoAIClient({
apiKey: '...',
telemetryEnabled: true,
});
await client.public.stats(); // emits an OTel span to stdout