Skip to main content

TypeScript SDK

The official SDK for integrating ASG Agent Cloud into your TypeScript/JavaScript applications.

Installation

npm install @asgcompute/sdk

Quick Start

import { ASGClient } from '@asgcompute/sdk';
import { Keypair } from '@solana/web3.js';

// Initialize client
const client = new ASGClient({
  endpoint: 'https://agent.asgcompute.com/mcp',
  wallet: Keypair.fromSecretKey(yourSecretKey),
  network: 'mainnet' // or 'devnet'
});

// Call a tool
const response = await client.callTool('inference_chat', {
  model: 'asg-fast',
  messages: [{ role: 'user', content: 'Hello!' }]
});

console.log(response.result.content);

Configuration

const client = new ASGClient({
  endpoint: string;          // Gateway URL
  wallet: Keypair;           // Solana wallet
  network: 'mainnet' | 'devnet';
  timeout?: number;          // Request timeout (ms)
  retries?: number;          // Auto-retry count
});

Core Methods

listTools()

List all available tools.
const tools = await client.listTools();
// [{ name: 'inference_chat', description: ... }, ...]

callTool(name, arguments)

Execute a tool with automatic payment handling.
const result = await client.callTool('sandbox_execute', {
  language: 'python',
  code: 'print("Hello!")'
});

getQuote(name, arguments)

Get a price quote without executing.
const quote = await client.getQuote('gpu_provision', {
  gpu_type: 'RTX_4090',
  ttl_seconds: 3600
});

console.log(`Cost: $${quote.amount_usdc / 1_000_000}`);

getReceipt(receiptId)

Retrieve a receipt by ID.
const receipt = await client.getReceipt('rcpt_abc123');
console.log(`Charged: ${receipt.debited_usdc_microusd}`);

Streaming

const stream = await client.callTool('inference_chat', {
  model: 'asg-fast',
  messages: [{ role: 'user', content: 'Write a poem' }],
  stream: true
});

for await (const chunk of stream) {
  process.stdout.write(chunk.content);
}

Error Handling

import { ASGError, QuoteExpiredError, BudgetExceededError } from '@asgcompute/sdk';

try {
  await client.callTool('inference_chat', { ... });
} catch (error) {
  if (error instanceof QuoteExpiredError) {
    // Quote expired, retry
  } else if (error instanceof BudgetExceededError) {
    // Budget limit hit
  } else if (error instanceof ASGError) {
    console.error(`ASG Error ${error.code}: ${error.message}`);
  }
}

TypeScript Types

import type { 
  Tool, 
  Quote, 
  Receipt, 
  InferenceChatArgs,
  GpuProvisionArgs 
} from '@asgcompute/sdk';

Next Steps