> ## 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.

# AI Tools

> User stories, technical specs, roadmaps, wireframes, and more

# AI Tools API

All AI tool endpoints use SSE streaming unless noted. They require authentication and are rate-limited.

## PRD Coach

```http theme={null}
POST /api/ai/coach
```

Get a CPO-level PRD review with scoring.

**Body:**

| Field         | Type   | Required | Description                                |
| ------------- | ------ | -------- | ------------------------------------------ |
| `prdContent`  | string | Yes      | PRD content to review                      |
| `projectName` | string | No       | Project name for context                   |
| `projectId`   | string | No       | Save review to project's stakeholder views |

<CodeGroup>
  ```bash curl theme={null}
  curl -N -X POST https://app.thig.ai/api/ai/coach \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -H "Accept: text/event-stream" \
    -d '{"prdContent": "# My PRD\n\n## Problem Statement\n...", "projectName": "Mobile App"}'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/ai/coach', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      prdContent: '# My PRD\n\n## Problem Statement\n...',
      projectName: 'Mobile App'
    })
  });

  const reader = res.body.getReader();
  const decoder = new TextDecoder();
  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    const chunk = decoder.decode(value);
    // Parse SSE lines for progress and content events
    for (const line of chunk.split('\n').filter(l => l.startsWith('data: '))) {
      const data = JSON.parse(line.slice(6));
      if (data.type === 'done') console.log('Review:', data.review);
    }
  }
  ```
</CodeGroup>

**SSE `done` payload:**

```json theme={null}
{
  "review": {
    "overallScore": 78,
    "executiveSummary": "...",
    "dimensions": { "clarity": 85, "completeness": 72, ... },
    "strengths": ["..."],
    "improvements": [{ "priority": "high", "suggestion": "..." }],
    "missingSections": ["..."],
    "recommendations": [{ "effort": "low", "impact": "high", "description": "..." }]
  }
}
```

## AI Improvements

### List Improvement Types

```http theme={null}
GET /api/ai/improve
```

Returns available improvement types.

### Apply Improvement (Streaming)

```http theme={null}
POST /api/ai/improve
```

**Body:**

| Field             | Type   | Required | Description                                                                                                                         |
| ----------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `content`         | string | Yes      | Text to improve                                                                                                                     |
| `improvementType` | string | Yes      | Type: `improve_writing`, `make_concise`, `add_detail`, `fix_grammar`, `make_technical`, `simplify`, `add_user_focus`, `add_metrics` |
| `customPrompt`    | string | No       | Custom improvement instructions                                                                                                     |

<CodeGroup>
  ```bash curl theme={null}
  curl -N -X POST https://app.thig.ai/api/ai/improve \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -H "Accept: text/event-stream" \
    -d '{"content": "The app lets users do stuff with their data.", "improvementType": "improve_writing"}'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/ai/improve', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      content: 'The app lets users do stuff with their data.',
      improvementType: 'improve_writing'
    })
  });

  const reader = res.body.getReader();
  const decoder = new TextDecoder();
  let improved = '';
  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    const chunk = decoder.decode(value);
    for (const line of chunk.split('\n').filter(l => l.startsWith('data: '))) {
      const data = JSON.parse(line.slice(6));
      if (data.type === 'content') improved += data.content;
    }
  }
  ```
</CodeGroup>

**Improvement Types:**

| Type              | Description                      |
| ----------------- | -------------------------------- |
| `improve_writing` | Better clarity and flow          |
| `make_concise`    | Shorten while preserving meaning |
| `add_detail`      | Expand with specifics            |
| `fix_grammar`     | Correct grammar and spelling     |
| `make_technical`  | Add technical depth              |
| `simplify`        | Plain language rewrite           |
| `add_user_focus`  | Center on user needs             |
| `add_metrics`     | Add measurable success criteria  |

## AI Suggestions

```http theme={null}
POST /api/ai/suggestions
```

Non-streaming. Analyzes PRD and returns 3-5 improvement suggestions.

**Body:**

| Field         | Type   | Required | Description            |
| ------------- | ------ | -------- | ---------------------- |
| `content`     | string | Yes      | PRD content to analyze |
| `projectName` | string | No       | Project name           |

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://app.thig.ai/api/ai/suggestions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"content": "# My PRD\n\n## Problem\nUsers need a faster way to...", "projectName": "Mobile App"}'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/ai/suggestions', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      content: '# My PRD\n\n## Problem\nUsers need a faster way to...',
      projectName: 'Mobile App'
    })
  });
  const { suggestions } = await res.json();
  ```
</CodeGroup>

**Response:**

```json theme={null}
{
  "suggestions": [
    {
      "id": "sug_1",
      "section": "Problem Statement",
      "type": "improvement",
      "title": "Add quantitative data",
      "description": "Consider adding market size or user pain point statistics",
      "severity": "warning"
    }
  ]
}
```

## User Stories (Streaming)

```http theme={null}
POST /api/ai/user-stories
```

**Body:**

| Field         | Type   | Required | Description                         |
| ------------- | ------ | -------- | ----------------------------------- |
| `content`     | string | Yes      | Source content                      |
| `source`      | string | Yes      | `prd`, `feature`, or `requirements` |
| `projectName` | string | No       | Project name                        |
| `projectId`   | string | No       | Save to project's stakeholder views |

<CodeGroup>
  ```bash curl theme={null}
  curl -N -X POST https://app.thig.ai/api/ai/user-stories \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -H "Accept: text/event-stream" \
    -d '{"content": "Users can create and share documents", "source": "prd", "projectName": "Docs App"}'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/ai/user-stories', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      content: 'Users can create and share documents',
      source: 'prd',
      projectName: 'Docs App'
    })
  });

  const reader = res.body.getReader();
  const decoder = new TextDecoder();
  let stories = '';
  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    const chunk = decoder.decode(value);
    for (const line of chunk.split('\n').filter(l => l.startsWith('data: '))) {
      const data = JSON.parse(line.slice(6));
      if (data.type === 'content') stories += data.content;
    }
  }
  ```
</CodeGroup>

## Technical Specs (Streaming)

```http theme={null}
POST /api/ai/technical-specs
```

**Body:**

| Field         | Type      | Required | Description                |
| ------------- | --------- | -------- | -------------------------- |
| `prdContent`  | string    | Yes      | PRD content                |
| `projectName` | string    | No       | Project name               |
| `focusAreas`  | string\[] | No       | Specific areas to focus on |
| `projectId`   | string    | No       | Save to project            |

<CodeGroup>
  ```bash curl theme={null}
  curl -N -X POST https://app.thig.ai/api/ai/technical-specs \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -H "Accept: text/event-stream" \
    -d '{"prdContent": "# PRD\n\n## Features\n- Real-time sync\n- Offline mode", "focusAreas": ["architecture", "data-model"]}'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/ai/technical-specs', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      prdContent: '# PRD\n\n## Features\n- Real-time sync\n- Offline mode',
      focusAreas: ['architecture', 'data-model']
    })
  });

  const reader = res.body.getReader();
  const decoder = new TextDecoder();
  let specs = '';
  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    const chunk = decoder.decode(value);
    for (const line of chunk.split('\n').filter(l => l.startsWith('data: '))) {
      const data = JSON.parse(line.slice(6));
      if (data.type === 'content') specs += data.content;
    }
  }
  ```
</CodeGroup>

## Implementation Roadmap

```http theme={null}
POST /api/ai/roadmap
```

Non-streaming.

**Body:**

| Field         | Type   | Required | Description                   |
| ------------- | ------ | -------- | ----------------------------- |
| `prdContent`  | string | Yes      | PRD content                   |
| `teamSize`    | string | Yes      | `small`, `medium`, or `large` |
| `methodology` | string | Yes      | Development methodology       |

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://app.thig.ai/api/ai/roadmap \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "prdContent": "# My PRD\n\n## Features\n- User auth\n- Dashboard\n- Reports",
      "teamSize": "small",
      "methodology": "agile"
    }'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/ai/roadmap', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      prdContent: '# My PRD\n\n## Features\n- User auth\n- Dashboard\n- Reports',
      teamSize: 'small',
      methodology: 'agile'
    })
  });
  const { roadmap } = await res.json();
  // roadmap contains phases with milestones, tasks, and timeline estimates
  ```
</CodeGroup>

## Code Spec (Streaming)

```http theme={null}
POST /api/ai/code-spec
```

Generate a developer specification sheet.

**Body:**

| Field       | Type   | Required | Description            |
| ----------- | ------ | -------- | ---------------------- |
| `content`   | string | Yes      | PRD content            |
| `projectId` | string | No       | Associate with project |
| `provider`  | string | No       | Force AI provider      |

<CodeGroup>
  ```bash curl theme={null}
  curl -N -X POST https://app.thig.ai/api/ai/code-spec \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -H "Accept: text/event-stream" \
    -d '{"content": "# E-commerce PRD\n\n## Features\n- Shopping cart\n- Checkout flow", "provider": "anthropic"}'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/ai/code-spec', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      content: '# E-commerce PRD\n\n## Features\n- Shopping cart\n- Checkout flow',
      provider: 'anthropic'
    })
  });

  const reader = res.body.getReader();
  const decoder = new TextDecoder();
  let spec = '';
  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    const chunk = decoder.decode(value);
    for (const line of chunk.split('\n').filter(l => l.startsWith('data: '))) {
      const data = JSON.parse(line.slice(6));
      if (data.type === 'content') spec += data.content;
    }
  }
  ```
</CodeGroup>

## Launch Content (Streaming)

```http theme={null}
POST /api/ai/launch-content
```

**Body:**

| Field         | Type   | Required | Description                                                                                       |
| ------------- | ------ | -------- | ------------------------------------------------------------------------------------------------- |
| `content`     | string | Yes      | PRD content                                                                                       |
| `contentType` | string | Yes      | `blog_post`, `press_release`, `social_media`, `email_announcement`, `demo_script`, or `changelog` |
| `projectId`   | string | No       | Associate with project                                                                            |
| `provider`    | string | No       | Force AI provider (`openai`, `anthropic`, `gemini`)                                               |

<CodeGroup>
  ```bash curl theme={null}
  curl -N -X POST https://app.thig.ai/api/ai/launch-content \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -H "Accept: text/event-stream" \
    -d '{
      "content": "# SaaS Analytics PRD\n\nReal-time dashboard for tracking...",
      "contentType": "blog_post"
    }'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/ai/launch-content', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      content: '# SaaS Analytics PRD\n\nReal-time dashboard for tracking...',
      contentType: 'blog_post'
    })
  });

  const reader = res.body.getReader();
  const decoder = new TextDecoder();
  let content = '';
  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    const chunk = decoder.decode(value);
    for (const line of chunk.split('\n').filter(l => l.startsWith('data: '))) {
      const data = JSON.parse(line.slice(6));
      if (data.type === 'content') content += data.content;
    }
  }
  ```
</CodeGroup>

## Wireframe / Diagrams (Streaming)

```http theme={null}
POST /api/ai/wireframe
```

**Body:**

| Field         | Type   | Required | Description                                                                                    |
| ------------- | ------ | -------- | ---------------------------------------------------------------------------------------------- |
| `content`     | string | Yes      | PRD content                                                                                    |
| `diagramType` | string | Yes      | `user_flow`, `system_architecture`, `screen_layout`, `data_flow`, `sequence`, or `journey_map` |
| `section`     | string | No       | Focus on a specific PRD section                                                                |
| `projectId`   | string | No       | Associate with project                                                                         |

<CodeGroup>
  ```bash curl theme={null}
  curl -N -X POST https://app.thig.ai/api/ai/wireframe \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -H "Accept: text/event-stream" \
    -d '{
      "content": "# User Management\n\nUsers can register, login, manage profiles...",
      "diagramType": "user_flow",
      "section": "Authentication"
    }'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/ai/wireframe', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      content: '# User Management\n\nUsers can register, login, manage profiles...',
      diagramType: 'user_flow',
      section: 'Authentication'
    })
  });

  const reader = res.body.getReader();
  const decoder = new TextDecoder();
  let mermaid = '';
  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    const chunk = decoder.decode(value);
    for (const line of chunk.split('\n').filter(l => l.startsWith('data: '))) {
      const data = JSON.parse(line.slice(6));
      if (data.type === 'content') mermaid += data.content;
    }
  }
  // mermaid contains a Mermaid.js diagram string
  ```
</CodeGroup>
