|
| 1 | +# REST API Reference |
| 2 | + |
| 3 | +CrewForm exposes a REST API via Supabase for programmatic access to your workspace. Authenticate using API keys created in **Settings → API Keys**. |
| 4 | + |
| 5 | +## Authentication |
| 6 | + |
| 7 | +All API requests require a REST API key in the `Authorization` header: |
| 8 | + |
| 9 | +```bash |
| 10 | +curl -H "Authorization: Bearer crfm_your_api_key" \ |
| 11 | + -H "Content-Type: application/json" \ |
| 12 | + https://your-project.supabase.co/rest/v1/agents |
| 13 | +``` |
| 14 | + |
| 15 | +### Creating API Keys |
| 16 | + |
| 17 | +1. Go to **Settings → API Keys** |
| 18 | +2. Click **Generate Key** |
| 19 | +3. Copy the key — it's only shown once |
| 20 | +4. The key is hashed (SHA-256) before storage for security |
| 21 | + |
| 22 | +## Endpoints |
| 23 | + |
| 24 | +All endpoints are accessed via the Supabase REST API at: |
| 25 | + |
| 26 | +``` |
| 27 | +https://<your-project>.supabase.co/rest/v1/<table> |
| 28 | +``` |
| 29 | + |
| 30 | +You also need the `apikey` header with your Supabase anon key: |
| 31 | + |
| 32 | +```bash |
| 33 | +curl -H "Authorization: Bearer crfm_your_api_key" \ |
| 34 | + -H "apikey: your-supabase-anon-key" \ |
| 35 | + https://your-project.supabase.co/rest/v1/agents |
| 36 | +``` |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## Agents |
| 41 | + |
| 42 | +### List Agents |
| 43 | + |
| 44 | +```http |
| 45 | +GET /rest/v1/agents?select=* |
| 46 | +``` |
| 47 | + |
| 48 | +**Response:** |
| 49 | + |
| 50 | +```json |
| 51 | +[ |
| 52 | + { |
| 53 | + "id": "uuid", |
| 54 | + "name": "Code Reviewer", |
| 55 | + "description": "Reviews code for bugs and best practices", |
| 56 | + "model": "claude-sonnet-4-20250514", |
| 57 | + "provider": "anthropic", |
| 58 | + "system_prompt": "You are a senior code reviewer...", |
| 59 | + "temperature": 0.3, |
| 60 | + "max_tokens": 4096, |
| 61 | + "tags": ["code", "review"], |
| 62 | + "workspace_id": "uuid", |
| 63 | + "created_at": "2026-01-15T10:00:00Z", |
| 64 | + "updated_at": "2026-01-15T10:00:00Z" |
| 65 | + } |
| 66 | +] |
| 67 | +``` |
| 68 | + |
| 69 | +### Create Agent |
| 70 | + |
| 71 | +```http |
| 72 | +POST /rest/v1/agents |
| 73 | +Content-Type: application/json |
| 74 | +
|
| 75 | +{ |
| 76 | + "name": "Code Reviewer", |
| 77 | + "model": "claude-sonnet-4-20250514", |
| 78 | + "provider": "anthropic", |
| 79 | + "system_prompt": "You are a senior code reviewer...", |
| 80 | + "workspace_id": "your-workspace-id" |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### Update Agent |
| 85 | + |
| 86 | +```http |
| 87 | +PATCH /rest/v1/agents?id=eq.{agent_id} |
| 88 | +Content-Type: application/json |
| 89 | +
|
| 90 | +{ |
| 91 | + "name": "Updated Name", |
| 92 | + "temperature": 0.5 |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +### Delete Agent |
| 97 | + |
| 98 | +```http |
| 99 | +DELETE /rest/v1/agents?id=eq.{agent_id} |
| 100 | +``` |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +## Tasks |
| 105 | + |
| 106 | +### List Tasks |
| 107 | + |
| 108 | +```http |
| 109 | +GET /rest/v1/tasks?select=*&order=created_at.desc |
| 110 | +``` |
| 111 | + |
| 112 | +**Query parameters for filtering:** |
| 113 | + |
| 114 | +| Parameter | Example | Description | |
| 115 | +|-----------|---------|-------------| |
| 116 | +| `status` | `eq.running` | Filter by status | |
| 117 | +| `priority` | `eq.high` | Filter by priority | |
| 118 | +| `agent_id` | `eq.{uuid}` | Filter by assigned agent | |
| 119 | + |
| 120 | +### Create Task |
| 121 | + |
| 122 | +```http |
| 123 | +POST /rest/v1/tasks |
| 124 | +Content-Type: application/json |
| 125 | +
|
| 126 | +{ |
| 127 | + "title": "Review PR #42", |
| 128 | + "description": "Review the authentication changes", |
| 129 | + "agent_id": "uuid", |
| 130 | + "priority": "high", |
| 131 | + "workspace_id": "your-workspace-id" |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +**Task statuses:** `pending`, `running`, `completed`, `failed`, `cancelled` |
| 136 | + |
| 137 | +**Task priorities:** `low`, `medium`, `high`, `critical` |
| 138 | + |
| 139 | +### Get Task Detail |
| 140 | + |
| 141 | +```http |
| 142 | +GET /rest/v1/tasks?id=eq.{task_id}&select=* |
| 143 | +``` |
| 144 | + |
| 145 | +--- |
| 146 | + |
| 147 | +## Teams |
| 148 | + |
| 149 | +### List Teams |
| 150 | + |
| 151 | +```http |
| 152 | +GET /rest/v1/teams?select=* |
| 153 | +``` |
| 154 | + |
| 155 | +### Create Team |
| 156 | + |
| 157 | +```http |
| 158 | +POST /rest/v1/teams |
| 159 | +Content-Type: application/json |
| 160 | +
|
| 161 | +{ |
| 162 | + "name": "Content Pipeline", |
| 163 | + "description": "Research → Write → Edit", |
| 164 | + "mode": "pipeline", |
| 165 | + "workspace_id": "your-workspace-id" |
| 166 | +} |
| 167 | +``` |
| 168 | + |
| 169 | +### Team Runs |
| 170 | + |
| 171 | +```http |
| 172 | +GET /rest/v1/team_runs?team_id=eq.{team_id}&select=*&order=created_at.desc |
| 173 | +``` |
| 174 | + |
| 175 | +--- |
| 176 | + |
| 177 | +## Usage Records |
| 178 | + |
| 179 | +### Query Usage |
| 180 | + |
| 181 | +```http |
| 182 | +GET /rest/v1/usage_records?select=*&created_at=gte.2026-01-01&order=created_at.desc |
| 183 | +``` |
| 184 | + |
| 185 | +**Response fields:** |
| 186 | + |
| 187 | +| Field | Type | Description | |
| 188 | +|-------|------|-------------| |
| 189 | +| `task_id` | uuid | Associated task | |
| 190 | +| `agent_id` | uuid | Agent that ran | |
| 191 | +| `provider` | string | LLM provider | |
| 192 | +| `model` | string | Model used | |
| 193 | +| `prompt_tokens` | integer | Input tokens | |
| 194 | +| `completion_tokens` | integer | Output tokens | |
| 195 | +| `estimated_cost_usd` | decimal | Estimated cost | |
| 196 | +| `billing_model` | string | `per-token` or `subscription-quota` | |
| 197 | + |
| 198 | +--- |
| 199 | + |
| 200 | +## Marketplace |
| 201 | + |
| 202 | +### Browse Agents |
| 203 | + |
| 204 | +```http |
| 205 | +GET /rest/v1/agents?is_marketplace=eq.true&select=* |
| 206 | +``` |
| 207 | + |
| 208 | +### Install Agent (RPC) |
| 209 | + |
| 210 | +```http |
| 211 | +POST /rest/v1/rpc/increment_install_count |
| 212 | +Content-Type: application/json |
| 213 | +
|
| 214 | +{ |
| 215 | + "agent_row_id": "uuid" |
| 216 | +} |
| 217 | +``` |
| 218 | + |
| 219 | +--- |
| 220 | + |
| 221 | +## Rate Limits |
| 222 | + |
| 223 | +The Supabase free tier includes: |
| 224 | +- **500 requests/minute** per API key |
| 225 | +- **50,000 requests/month** total |
| 226 | + |
| 227 | +For higher limits, upgrade your Supabase plan. |
| 228 | + |
| 229 | +## Error Handling |
| 230 | + |
| 231 | +All errors follow the standard Supabase/PostgREST format: |
| 232 | + |
| 233 | +```json |
| 234 | +{ |
| 235 | + "code": "PGRST301", |
| 236 | + "message": "Row not found", |
| 237 | + "details": null, |
| 238 | + "hint": null |
| 239 | +} |
| 240 | +``` |
| 241 | + |
| 242 | +Common error codes: |
| 243 | + |
| 244 | +| HTTP Status | Meaning | |
| 245 | +|-------------|---------| |
| 246 | +| `401` | Missing or invalid API key | |
| 247 | +| `403` | Row-Level Security denied access | |
| 248 | +| `404` | Resource not found | |
| 249 | +| `409` | Conflict (duplicate key) | |
| 250 | +| `422` | Validation error | |
0 commit comments