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

# Regenerate Prompts

> Manually regenerate AI visibility prompts for a business or product

<Warning>
  **Manual Trigger Endpoint** - This endpoint is for debugging and manual intervention only. It is NOT called by the daily cron job.

  Prompts are normally generated:

  * During **onboarding** via `/api/onboarding/generate-all`
  * When **new products are discovered** via `/api/cron/discover-products-from-changes`
</Warning>

## Overview

Manually regenerates the AI visibility prompts for a business or product. This endpoint scrapes the website fresh and generates new prompts using Gemini.

**Use cases:**

* Debugging prompt generation issues
* Refreshing prompts after significant website content changes
* Testing prompt generation for a specific entity

<Note>
  This endpoint requires API key authentication (`X-API-Key` header).
</Note>

## Prompt Limits

| Entity Type  | Prompts | Notes                                        |
| ------------ | ------- | -------------------------------------------- |
| **Business** | 50      | 10 via Exa (onboarding only) + 40 via Gemini |
| **Products** | 10 each | Unlimited products                           |

<Info>
  This endpoint regenerates prompts via Gemini only. The 10 pre-tested Exa prompts are only generated during onboarding.
</Info>

## Request Body

<ParamField body="business_id" type="string" required>
  Business identifier (clerk org slug)
</ParamField>

<ParamField body="url" type="string" required>
  Website URL to scrape for prompt generation
</ParamField>

<ParamField body="product_id" type="string">
  Optional product ID for product-specific prompts
</ParamField>

<ParamField body="prompt_count" type="integer" default="50">
  Number of prompts to generate (default: 50 for business, 10 for product)
</ParamField>

## Response

<ResponseField name="status" type="string">
  `success`, `skipped`, or `error`
</ResponseField>

<ResponseField name="prompts_generated" type="integer">
  Number of prompts generated by Gemini
</ResponseField>

<ResponseField name="prompts_saved" type="integer">
  Number of prompts saved to database
</ResponseField>

<ResponseField name="skipped_reason" type="string">
  Reason for skipping (if status is `skipped`)
</ResponseField>

<ResponseField name="error" type="string">
  Error message if status is `error`
</ResponseField>

## Example

<CodeGroup>
  ```bash Request (Business) theme={null}
  curl -X POST "https://searchcompany-main.up.railway.app/api/manual-trigger/regenerate-prompts" \
    -H "X-API-Key: search-company" \
    -H "Content-Type: application/json" \
    -d '{
      "business_id": "acme-corp-123456",
      "url": "https://www.acme.com",
      "prompt_count": 50
    }'
  ```

  ```bash Request (Product) theme={null}
  curl -X POST "https://searchcompany-main.up.railway.app/api/manual-trigger/regenerate-prompts" \
    -H "X-API-Key: search-company" \
    -H "Content-Type: application/json" \
    -d '{
      "business_id": "acme-corp-123456",
      "url": "https://www.acme.com/widget-pro",
      "product_id": "widget-pro",
      "prompt_count": 10
    }'
  ```

  ```json Response (Success) theme={null}
  {
    "status": "success",
    "prompts_generated": 50,
    "prompts_saved": 50
  }
  ```

  ```json Response (Error) theme={null}
  {
    "status": "error",
    "prompts_generated": 0,
    "prompts_saved": 0,
    "error": "Failed to scrape website"
  }
  ```
</CodeGroup>

## Internal Process

This endpoint calls the `generate_prompts` service which:

1. **Scrapes the website** using Firecrawl (up to 5000 pages)
2. **Generates prompts** using Gemini 3 Flash
3. **Saves prompts** to the `entity_prompts_tracker` table

The prompts are questions that AI platforms might use when recommending businesses. They are checked via daily sampling (10 prompts/day) against 8 AI platforms to calculate visibility scores.

## Notes

* Prompts should NOT contain the business name (we test if AI recommends them organically)
* Regenerating prompts does NOT delete existing prompts - it adds new ones
* Visibility results for new prompts will be `null` until tested by the daily cron job
* Pre-tested Exa prompts (from onboarding) are not affected by regeneration
