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

# API Reference

> thig.ai REST API overview

# API Reference

The thig.ai API provides programmatic access to projects, PRDs, templates, AI tools, exports, and more.

## Base URL

```
https://app.thig.ai/api
```

## Authentication

All API requests require authentication via session cookies or API keys. See [Authentication](/api-reference/authentication) for details.

## Response Format

### Success Response

```json theme={null}
{
  "success": true,
  "data": { ... }
}
```

Some endpoints return the data directly without a wrapper:

```json theme={null}
{
  "projects": [...],
  "total": 42
}
```

### Error Response

```json theme={null}
{
  "error": "Error message describing what went wrong",
  "code": "ERROR_CODE"
}
```

### Common HTTP Status Codes

| Code  | Meaning                                                  |
| ----- | -------------------------------------------------------- |
| `200` | Success                                                  |
| `201` | Created                                                  |
| `400` | Bad Request — invalid input                              |
| `401` | Unauthorized — not authenticated                         |
| `403` | Forbidden — insufficient permissions or feature disabled |
| `404` | Not Found                                                |
| `429` | Rate Limited — too many requests                         |
| `500` | Internal Server Error                                    |

## Rate Limiting

API requests are rate-limited based on:

* **Subscription tier** — Higher plans get higher limits
* **Endpoint type** — AI endpoints have stricter limits than CRUD endpoints

When rate limited, you'll receive a `429` response. Wait and retry after the indicated period.

## Streaming Endpoints

AI-powered endpoints use **Server-Sent Events (SSE)** for streaming responses. Event types:

| Event Type | Description                                                          |
| ---------- | -------------------------------------------------------------------- |
| `progress` | Phase update with percentage (e.g., "Analyzing requirements... 25%") |
| `content`  | Text content chunk                                                   |
| `done`     | Final complete result                                                |
| `error`    | Error with message and optional code                                 |

### Handling SSE Streams

```javascript theme={null}
const response = await fetch('/api/generate-prd/stream', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ projectId: 'xxx' })
});

const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;

  const text = decoder.decode(value);
  const lines = text.split('\n');

  for (const line of lines) {
    if (line.startsWith('data: ')) {
      const event = JSON.parse(line.slice(6));
      // Handle event based on event.type
    }
  }
}
```

## Feature Flags

Some endpoints are gated by feature flags and may return `403` if the feature is disabled for your organization. Feature-gated endpoints are noted in their documentation.

## API Sections

<CardGroup cols={2}>
  <Card title="Projects" icon="folder-open" href="/api-reference/projects">
    CRUD operations for PRD projects
  </Card>

  <Card title="Chat & PRD Generation" icon="comments" href="/api-reference/chat">
    AI conversation and PRD generation
  </Card>

  <Card title="AI Tools" icon="wand-magic-sparkles" href="/api-reference/ai-tools">
    User stories, tech specs, roadmaps, wireframes
  </Card>

  <Card title="Templates" icon="puzzle-piece" href="/api-reference/templates">
    Template CRUD and marketplace
  </Card>

  <Card title="Exports" icon="download" href="/api-reference/exports">
    PDF, DOCX, HTML, Notion, Google Docs export
  </Card>

  <Card title="Organization" icon="building" href="/api-reference/organization">
    Org settings, members, branding, domain
  </Card>

  <Card title="User" icon="user" href="/api-reference/user">
    Profile, BYOK keys, onboarding, data export
  </Card>

  <Card title="Webhooks & Integrations" icon="plug" href="/api-reference/webhooks">
    Outgoing webhooks and third-party integrations
  </Card>

  <Card title="Notifications" icon="bell" href="/api-reference/notifications">
    In-app notifications, preferences, scheduled exports
  </Card>

  <Card title="Usage & Billing" icon="chart-bar" href="/api-reference/usage">
    Usage metrics, plan limits, billing management
  </Card>

  <Card title="Admin & Enterprise" icon="shield-halved" href="/api-reference/admin">
    Teams, approval workflows, audit logs, IP allowlist
  </Card>
</CardGroup>
