REST API Reference
Complete reference for the Cosmo REST API.
The Cosmo REST API provides programmatic access to all Cosmo resources. All endpoints require authentication unless noted, and are scoped to the authenticated user's organization.
Base URL: https://api.cosmo.dev/api/v1
Authentication
Most endpoints require a Clerk JWT. Pass it in the Authorization header:
Authorization: Bearer <clerk_token>Some flows issue a Cosmo JWT (via the exchange-token endpoint). Admin-only endpoints use a separate admin secret header.
Roles
| Role | Description |
|---|---|
OWNER | Full control — billing, members, org settings |
ADMIN | Manage members, invites, app settings |
MEMBER | Default — access to workspaces and AI |
VIEWER | Read-only access |
Auth
Exchange Token
POST /auth/exchange-tokenExchange a Clerk JWT for a Cosmo JWT. Called by the desktop app on sign-in. Creates or syncs the user and org in Cosmo's database.
Request body:
| Field | Type | Required | Description |
|---|---|---|---|
clerkToken | string | Yes | Clerk JWT |
userName | string | No | Display name |
userEmail | string | No | Email address |
userAvatarUrl | string | No | Avatar URL |
orgName | string | No | Org display name |
orgSlug | string | No | Org slug |
Response:
{
"token": "cosmo.jwt...",
"user": { "id": "...", "name": "...", "email": "..." },
"org": { "id": "...", "name": "...", "slug": "..." },
"role": "OWNER",
"onboardingCompleted": false,
"onboardingSeeded": false
}Refresh Token
POST /auth/refreshRefresh an expired Cosmo JWT. There is a 7-day grace window after expiry.
Request body:
{ "token": "<expired_cosmo_jwt>" }Response: Same shape as exchange-token.
Get Current User
GET /auth/meAuth: Clerk JWT
Returns the authenticated user's profile, org, and role.
Mark Onboarding Complete
POST /auth/onboarding-completeAuth: Clerk JWT
Marks the current user's onboarding as complete.
Seed Onboarding
POST /auth/seed-onboardingAuth: Clerk JWT
Idempotent — creates the shared team, shared workspace, and sample tasks for a new org. Safe to call multiple times.
CLI Auth
GET /auth/cli-auth?port=<port>&state=<state>
GET /auth/cli-callback?port=<port>&state=<state>Two-step CLI authentication flow. The CLI opens the first URL in a browser, which redirects to Clerk sign-in. After sign-in, Clerk redirects to the callback, which mints a Cosmo JWT and posts it back to the CLI's local HTTP server.
Organization
All org endpoints require Clerk JWT.
List Members
GET /org/membersReturns all members of the authenticated user's org.
Update Member Role
PATCH /org/members/:userId/roleRequired role: OWNER
{ "role": "ADMIN" }Remove Member
DELETE /org/members/:userIdRequired role: OWNER or ADMIN
List Invites
GET /org/invitesReturns all pending invites.
Invite User
POST /org/inviteRequired role: OWNER or ADMIN
{ "email": "alice@example.com", "role": "MEMBER" }Resend Invite
POST /org/invite/:id/resendRequired role: OWNER or ADMIN
Revoke Invite
DELETE /org/invite/:idRequired role: OWNER or ADMIN
Chat
Stream Chat Response
POST /chatAuth: Clerk JWT + quota check
Streams an LLM response as Server-Sent Events (text/event-stream). See SSE Events for the full event schema.
Request body:
| Field | Type | Required | Description |
|---|---|---|---|
message | string | Yes | User's message |
history | HistoryMessage[] | No | Prior conversation turns |
tools | ToolDefinition[] | No | Client-defined tool schemas |
model | string | No | Model ID (default: claude-sonnet-4-20250514) |
maxTokens | number | No | Max output tokens |
systemPrompt | string | No | Custom system prompt |
enableWebSearch | boolean | No | Enable web search built-in tool |
Response: text/event-stream — see SSE Events.
List Models
GET /modelsAuth: Clerk JWT
Returns the list of available LLM models.
Tasks
All task endpoints require Clerk JWT. Tasks are scoped to the authenticated user's org.
List Tasks
GET /tasksQuery parameters:
| Param | Type | Description |
|---|---|---|
status | TaskStatus | Filter by status |
priority | TaskPriority | Filter by priority |
assigneeId | string | Filter by assignee user ID |
workspaceId | string | Filter by workspace |
tags | string | Comma-separated tag list |
dueBefore | string | ISO date — tasks due before this |
dueAfter | string | ISO date — tasks due after this |
Get Task
GET /tasks/:idCreate Task
POST /tasks| Field | Type | Required | Description |
|---|---|---|---|
title | string | Yes | Task title |
description | string | No | Detailed description |
status | TaskStatus | No | Default: TODO |
priority | TaskPriority | No | Default: MEDIUM |
assigneeId | string | No | Assignee user ID (null = unassigned, visible to all org members) |
workspaceId | string | No | Workspace ID (null = org-level) |
dueDate | string | No | ISO date string |
tags | string[] | No | Tag list |
metadata | object | No | Arbitrary JSON |
TaskStatus values: TODO · IN_PROGRESS · DONE · CANCELLED
TaskPriority values: LOW · MEDIUM · HIGH · URGENT
When status changes to DONE, completedAt is set automatically. When changed away from DONE, it is cleared.
Update Task
PATCH /tasks/:idPartial update — send only the fields to change.
Delete Task
DELETE /tasks/:idReorder Tasks
POST /tasks/reorderBulk-update sortOrder for drag-and-drop. Send an ordered array of task IDs — the server assigns sortOrder based on position in the array.
{ "taskIds": ["task_abc", "task_def", "task_ghi"] }Reprioritize Tasks
POST /tasks/reprioritizeApply AI-driven priority changes. Each change requires taskId and reason; priority and sortOrder are optional.
{
"changes": [
{ "taskId": "task_abc", "priority": "HIGH", "reason": "Customer deadline moved up" }
]
}Teams
All team endpoints require Clerk JWT.
List Teams
GET /teamsReturns all teams the current user belongs to.
Get Team
GET /teams/:idCreate Team
POST /teams| Field | Type | Required |
|---|---|---|
name | string | Yes |
description | string | No |
Update Team
PATCH /teams/:idDelete Team
DELETE /teams/:idList Team Members
GET /teams/:id/membersAdd Team Member
POST /teams/:id/members{ "userId": "user_..." }Remove Team Member
DELETE /teams/:id/members/:userIdWorkspaces
All workspace endpoints require Clerk JWT.
List Workspaces
GET /workspaces?teamId=<teamId>Returns workspaces the current user can access. Filter by teamId to scope to a specific team.
Get Workspace
GET /workspaces/:idCreate Workspace
POST /workspaces| Field | Type | Required |
|---|---|---|
name | string | Yes |
teamId | string | Yes |
description | string | No |
Update Workspace
PATCH /workspaces/:idDelete Workspace
DELETE /workspaces/:idMove Workspace
POST /workspaces/:id/moveMoves the workspace to another team.
{ "targetTeamId": "team_..." }Reorder Workspaces
PUT /workspaces/orderUpdates the visual sort order of workspaces for the current user.
Request body:
{
"order": ["workspace_id_1", "workspace_id_2", "workspace_id_3"]
}Response:
{ "success": true }Connectors (MCP)
All connector endpoints require Clerk JWT. Connectors are scoped to the org.
List Connectors
GET /connectorsReturns all MCP connector instances for the org.
Create Connector
POST /connectors| Field | Type | Required | Description |
|---|---|---|---|
providerId | string | Yes | Provider identifier (e.g., notion, github) |
name | string | No | Display name override |
config | object | No | Provider-specific config |
Get Credentials
GET /connectors/:instanceId/credentialsReturns the stored credentials for a connector instance.
Update Credentials
POST /connectors/:instanceId/credentials{ "credentials": { "apiKey": "sk-..." } }Delete Connector
DELETE /connectors/:instanceIdBilling
Mutation endpoints additionally require the OWNER or ADMIN role.
Get Billing Status
GET /billing/statusAuth: Clerk JWT
Returns the subscription gate status — whether the org can access the product.
Response:
{
"allowed": true,
"plan": "STANDARD",
"status": "TRIALING",
"trialEndsAt": "2026-05-19T00:00:00Z"
}Plan values: NO_PLAN · FREE · STANDARD · PREMIUM · ENTERPRISE
Status values: TRIALING · ACTIVE · PAST_DUE · CANCELED · PAUSED
Plan lifecycle: NO_PLAN → TRIALING/STANDARD (14-day trial) → ACTIVE (paid) → FREE (cancelled).
Get Subscription
GET /billing/subscriptionAuth: Clerk JWT
Returns detailed subscription info.
Start Trial
POST /billing/trialRequired role: OWNER or ADMIN
Starts a 14-day Standard trial. Can only be called once per org.
Create Checkout Session
POST /billing/checkoutRequired role: OWNER or ADMIN
{ "plan": "STANDARD" }Returns a Stripe checkout session URL. Redirect the user to this URL to complete payment.
Create Portal Session
POST /billing/portalRequired role: OWNER or ADMIN
Returns a Stripe customer portal URL for managing the subscription.
Downgrade to Free
POST /billing/downgradeRequired role: OWNER or ADMIN
Cancels the active subscription and downgrades to the Free plan at the end of the billing period.
Metering & Quotas
All metering endpoints require Clerk JWT.
Get Org Usage
GET /metering/orgReturns token usage summary for the org's current billing period.
Get User Usage
GET /metering/userReturns token usage for the current user in the current billing period.
Get Quota Status
GET /metering/quotaReturns the current user's daily quota status.
{
"used": 45000,
"limit": 100000,
"remaining": 55000,
"resetsAt": "2026-05-06T00:00:00Z"
}Updates
Check for Updates
GET /updates/checkAuth: None (public)
Query parameters:
| Param | Type | Required | Description |
|---|---|---|---|
version | string | Yes | Current app version |
platform | string | Yes | darwin · win32 · linux |
arch | string | Yes | x64 · arm64 |
channel | string | No | stable (default) · beta |
clientId | string | No | For rollout percentage bucketing |
Returns update info if a newer version is available, or null if up to date.
{
"version": "2026.5.1",
"downloadUrl": "https://...",
"releaseNotes": "...",
"mandatory": false,
"sha512": "...",
"fileSizeBytes": 102400000
}Error Responses
All error responses follow a standard shape:
{
"statusCode": 400,
"message": "Validation failed",
"error": "Bad Request"
}| Status | Meaning |
|---|---|
400 | Bad request — missing or invalid fields |
401 | Unauthenticated — missing or invalid token |
403 | Forbidden — insufficient role or quota exceeded |
404 | Resource not found |
429 | Rate limited |
500 | Internal server error |
Webhooks
Cosmo receives webhooks from Clerk and Stripe. These are internal endpoints verified by signature and not intended for direct use.
| Endpoint | Source | Verification |
|---|---|---|
POST /auth/webhook | Clerk | Svix signature header |
POST /billing/webhook | Stripe | Stripe-Signature header |