# API Reference

## HTTP Endpoints

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/health` | GET | Health check |
| `/api/sessions` | GET | List active sessions |
| `/api/session/:key` | GET | Get session details |
| `/api/cron/jobs` | GET | List cron jobs |
| `/api/cron/jobs/:id` | GET | Get cron job details |
| `/api/config` | GET | Get current config (secrets redacted) |
| `/hooks/wake` | POST | Webhook trigger |

### Health Check

```bash
curl http://localhost:52134/health
# Response: { "status": "ok" }
```

### Sessions

```bash
curl http://localhost:52134/api/sessions
# Response: [{ "key": "agent:default:telegram:dm:123", "status": "active" }]
```

## WebSocket Protocol

Connect to `ws://localhost:52134/ws`

### Methods

| Method | Description |
|--------|-------------|
| `session.list` | List sessions |
| `session.get` | Get session details |
| `session.kill` | Kill a session |
| `cron.list` | List cron jobs |
| `cron.run` | Trigger a cron job |
| `cron.pause` | Pause a cron job |
| `cron.resume` | Resume a cron job |
| `config.reload` | Reload configuration |
| `gateway.restart` | Restart gateway |

### Example

```javascript
const ws = new WebSocket('ws://localhost:52134/ws');

ws.send(JSON.stringify({
  method: 'session.list',
  params: {}
}));

ws.onmessage = (event) => {
  console.log(JSON.parse(event.data));
};
```

## Agent Tools

Agents have access to these gateway tools:

| Tool | Description |
|------|-------------|
| `send_message` | Send text message to channel |
| `send_media` | Send media file to channel |
| `message` | React/edit/delete/pin messages |
| `cron` | Manage cron jobs |
| `gateway` | Gateway management (reload/restart) |
| `session_status` | Query session runtime status |
