> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kodostatus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK

> Official SDKs for integrating Kodo into your applications

Use our SDKs to integrate status updates directly into your application code.

## JavaScript / TypeScript

### Installation

```bash theme={null}
npm install kodo-sdk
```

### Quick Start

```javascript theme={null}
import { Kodo } from 'kodo-sdk';

const kodo = new Kodo({
  apiKey: process.env.KODO_API_KEY
});

// Update service status
await kodo.services.update('api-gateway', {
  status: 'degraded'
});

// Create incident
await kodo.incidents.create({
  title: 'High latency detected',
  status: 'investigating',
  severity: 'minor',
  services: ['api-gateway']
});

// Send heartbeat
await kodo.heartbeat('worker-1');
```

### Service Methods

```javascript theme={null}
// List services
const services = await kodo.services.list();

// Get service
const service = await kodo.services.get('svc_abc123');

// Update status
await kodo.services.update('api-gateway', {
  status: 'operational'
});
```

### Incident Methods

```javascript theme={null}
// List incidents
const incidents = await kodo.incidents.list({
  status: 'investigating'
});

// Create incident
const incident = await kodo.incidents.create({
  title: 'Database issues',
  status: 'investigating',
  severity: 'major',
  services: ['database'],
  message: 'We are investigating'
});

// Add update
await kodo.incidents.update(incident.id, {
  status: 'identified',
  message: 'Root cause found'
});

// Resolve
await kodo.incidents.resolve(incident.id, {
  message: 'Issue resolved'
});
```

### Monitor Methods

```javascript theme={null}
// List monitors
const monitors = await kodo.monitors.list();

// Create monitor
const monitor = await kodo.monitors.create({
  name: 'API Health',
  url: 'https://api.example.com/health',
  interval: 300
});

// Pause monitor
await kodo.monitors.disable(monitor.id);
```

### Heartbeat

```javascript theme={null}
// Simple heartbeat
await kodo.heartbeat('hb_abc123');

// With status
await kodo.heartbeat('hb_abc123', {
  status: 'up',
  message: 'Job completed successfully',
  duration: 1523
});

// Report failure
await kodo.heartbeat('hb_abc123', {
  status: 'down',
  message: 'Job failed'
});
```

## Express Middleware

```javascript theme={null}
import { createKodoMiddleware } from '@kodo-status/express';

const kodo = createKodoMiddleware({
  apiKey: process.env.KODO_API_KEY,
  monitorId: process.env.KODO_MONITOR_ID
});

// Health endpoint
app.get('/health', kodo.healthCheck);

// Error tracking (add as last middleware)
app.use(kodo.errorHandler);
```

## Next.js

```javascript theme={null}
// app/api/health/route.ts
import { createHealthHandler } from '@kodo-status/nextjs';

export const GET = createHealthHandler({
  apiKey: process.env.KODO_API_KEY,
  monitorId: process.env.KODO_MONITOR_ID
});
```

## Error Handling

```javascript theme={null}
import { KodoError } from 'kodo-sdk';

try {
  await kodo.incidents.create({ ... });
} catch (error) {
  if (error instanceof KodoError) {
    console.error(`Kodo error: ${error.code} - ${error.message}`);
  }
}
```

## TypeScript

Full TypeScript support with types:

```typescript theme={null}
import { Kodo, Incident, Service, IncidentStatus } from 'kodo-sdk';

const kodo = new Kodo({ apiKey: '...' });

const incident: Incident = await kodo.incidents.create({
  title: 'Issue',
  status: 'investigating' as IncidentStatus
});
```
