Official TypeScript/Node.js SDK for AgentGate
npm install @agentgate/sdk
import { AgentGate } from '@agentgate/sdk'; // Initialize client const client = new AgentGate({ apiKey: process.env.AGENTGATE_API_KEY }); // Create a work order const workOrder = await client.workOrders.create({ taskPrompt: "Add comprehensive error handling to the API routes", workspaceSource: { type: "git", repository: "https://github.com/your-org/your-repo", branch: "main" } }); console.log('Run ID:', workOrder.runId); // Check run status const run = await client.runs.get(workOrder.runId); console.log('Status:', run.status);
const client = new AgentGate({ apiKey: 'org_live_xxxxx' });
const client = new AgentGate({ apiKey: process.env.AGENTGATE_API_KEY, baseUrl: 'https://agentgate.mynewapi.com', // Optional timeout: 30000, // Request timeout in ms retries: 3, // Number of retries on failure });
export AGENTGATE_API_KEY=org_live_xxxxx
// No need to pass apiKey const client = new AgentGate();
const workOrder = await client.workOrders.create({ taskPrompt: "Your task description", workspaceSource: { type: "git", repository: "https://github.com/org/repo", branch: "main" }, // Optional maxIterations: 10, tenantContext: { tenantId: "acme-corp", tenantUserId: "user_123" }, metadata: { ticketId: "PROJ-123" } });
const workOrder = await client.workOrders.get('wo_abc123');
const runs = await client.runs.list({ status: 'succeeded', limit: 10 }); for (const run of runs.data) { console.log(run.id, run.status); }
const run = await client.runs.get('run_abc123'); if (run.status === 'succeeded') { console.log('PR URL:', run.prUrl); }
await client.runs.cancel('run_abc123');
const balance = await client.credits.getBalance(); console.log('Total:', balance.totalCreditsCents); console.log('Included:', balance.includedCreditsCents); console.log('Purchased:', balance.purchasedCreditsCents);
const usage = await client.credits.getUsage({ startDate: '2024-01-01', endDate: '2024-01-31', tenantId: 'acme-corp' // Optional filter }); for (const tx of usage.transactions) { console.log(tx.createdAt, tx.amount, tx.runId); }
const webhook = await client.webhooks.create({ url: 'https://your-app.com/webhooks/agentgate', events: ['run.completed', 'run.failed'], description: 'Production webhook' }); // Save the secret immediately - only shown once! console.log('Secret:', webhook.secret);
const webhooks = await client.webhooks.list();
await client.webhooks.update('wh_abc123', { events: ['run.completed', 'run.failed', 'run.cancelled'], enabled: true });
await client.webhooks.delete('wh_abc123');
const result = await client.webhooks.test('wh_abc123'); console.log('Success:', result.success);
const templates = await client.templates.list();
const template = await client.templates.create({ id: 'my-api-template', name: 'My API Template', source: { type: 'git', repository: 'https://github.com/org/template' }, variables: [ { name: 'projectName', required: true } ] });
import { AgentGateError, AuthenticationError, PaymentError, RateLimitError, ValidationError } from '@agentgate/sdk'; try { await client.workOrders.create(/* ... */); } catch (error) { if (error instanceof AuthenticationError) { console.error('Invalid API key'); } else if (error instanceof PaymentError) { console.error('Insufficient credits:', error.details); } else if (error instanceof RateLimitError) { console.error('Rate limited, retry after:', error.retryAfter); } else if (error instanceof ValidationError) { console.error('Validation errors:', error.errors); } else if (error instanceof AgentGateError) { console.error('API error:', error.code, error.message); } }
import type { WorkOrder, Run, RunStatus, CreditBalance, Webhook, WebhookEvent, Template, CreateWorkOrderRequest, TenantContext } from '@agentgate/sdk';