Dobby

JavaScript / TypeScript SDK

npm install @dobbyai/sdk — Node.js 18+, TypeScript-native, ESM & CJS.

Requires a Dobby Gateway API key. Get one from your Gateway dashboard.

Installation

npm install @dobbyai/sdk

Basic Usage — LLM Completions

import { DobbyClient } from '@dobbyai/sdk';

const client = new DobbyClient({
  apiKey: 'gk_user_...',
  orgId: 'org_...',
  tenantId: 'tenant_...',
});

// LLM Completions (OpenAI-compatible)
const response = await client.chat.completions.create({
  model: 'claude-sonnet-4-20250514',
  messages: [{ role: 'user', content: 'Explain AI agents in 3 sentences' }],
  max_tokens: 200,
});
console.log(response.choices[0].message.content);

Streaming

// Streaming
const stream = await client.chat.completions.create({
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: 'Write a haiku about agents' }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}

Task Management

// Create a task
const task = await client.tasks.create({
  title: 'Fix authentication bug',
  description: 'Login fails for SSO users',
  priority: 'high',
  agent_name: 'dobby-backend-agent',
});
console.log(`Task created: ${task.id}`);

// List pending tasks
const pending = await client.tasks.list({ status: 'pending' });

// Update task status
await client.tasks.update(task.id, { status: 'in_progress' });

Approvals (Human-in-the-Loop)

// List pending approvals
const pending = await client.approvals.list({ status: 'pending' });

// Approve
await client.approvals.approve('task_abc123', 'LGTM, ship it!');

// Reject with reason
await client.approvals.reject('task_def456', 'Needs more test coverage');

Agent Fleet Management

// List fleet agents
const agents = await client.agents.list();

// Register an external agent
const agent = await client.agents.register({
  display_name: 'Research Agent',
  framework: 'crewai',
  protocol: 'a2a',
  endpoint_url: 'https://my-agent.example.com',
  capabilities: ['research', 'summarization'],
});
console.log(`Agent: ${agent.agent_id}`);
console.log(`Key: ${agent.gateway_key_secret}`);

// Pause/resume
await client.agents.pause(agent.agent_id);
await client.agents.resume(agent.agent_id);

External Agent Triggers & Schedules

// Trigger an external agent immediately
const result = await client.agents.trigger('ext_abc123', {
  payload: { topic: 'AI governance blog post' },
});
console.log(`Trigger: ${result.trigger_id} — ${result.status}`);

// Create a recurring schedule
await client.agents.createSchedule('ext_abc123', {
  name: 'Daily Blog Writer',
  schedule_config: { frequency: 'daily', time: '09:00' },
  task_title: 'Write blog post',
  trigger_payload: { topic: 'AI governance' },
});

// Get trigger history with stats
const history = await client.agents.triggers('ext_abc123', {
  include_stats: true,
});
console.log(`Completed: ${history.stats.completed}`);

// Retry a failed trigger
await client.agents.retryTrigger('ext_abc123', 'trig_failed_id');

// Manage schedule
await client.agents.updateSchedule('ext_abc123', { paused: true });
await client.agents.deleteSchedule('ext_abc123');

Cost Tracking (FinOps)

// Organization cost summary
const summary = await client.costs.summary({ period: '30d' });
console.log(`Total: $${summary.total_cost_usd?.toFixed(2)}`);

// Per-agent breakdown
const agentCosts = await client.costs.byAgent({ period: '7d' });

// Single agent deep-dive
const profile = await client.costs.agentProfile('ext_abc123');

Error Handling

import {
  DobbyAuthError,
  DobbyRateLimitError,
  DobbyBudgetExceededError,
  DobbyNotFoundError,
} from '@dobbyai/sdk';

try {
  const response = await client.chat.completions.create({
    model: 'claude-sonnet-4-20250514',
    messages: [{ role: 'user', content: 'Hello' }],
  });
} catch (err) {
  if (err instanceof DobbyAuthError) {
    console.error('Invalid or expired API key');
  } else if (err instanceof DobbyRateLimitError) {
    console.error(`Rate limited. Retry after: ${err.retryAfter}s`);
  } else if (err instanceof DobbyBudgetExceededError) {
    console.error('Budget limit reached');
  } else if (err instanceof DobbyNotFoundError) {
    console.error('Resource not found');
  }
}

Environment Variables

# Environment variables (alternative to constructor params)
DOBBY_API_KEY=gk_user_...
DOBBY_BASE_URL=https://dobby-ai.com
DOBBY_ORG_ID=org_...
DOBBY_TENANT_ID=tenant_...

// Then just:
const client = new DobbyClient(); // Auto-reads from env