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

# Fetch Competitors from Exa

<Note>
  **Internal Service** — This is not an HTTP endpoint. It's called by the competitor research service.
</Note>

## Purpose

Step 2 of competitor research: Uses Exa's Answer API to find 5 competitors based on the website content.

## Function Signature

```python theme={null}
async def fetch_competitors_from_exa(api_key: str, url: str, website_content: str) -> list
```

## Parameters

| Parameter         | Type  | Description                            |
| ----------------- | ----- | -------------------------------------- |
| `api_key`         | `str` | Exa API key                            |
| `url`             | `str` | Business URL (to exclude from results) |
| `website_content` | `str` | Content from Step 1                    |

## Returns

```python theme={null}
[
    {
        "name": "Competitor A",
        "website": "https://competitor-a.com",
        "strengths": ["strength 1", "strength 2", "strength 3"],
        "favicon_url": "https://..."
    },
    # ... 5 total
]
```

## Prompt Engineering

The prompt instructs Exa to:

1. Find exactly 5 competitors
2. NOT include the original business
3. Return 3 unique strengths per competitor (10-20 chars each)
4. Return valid JSON format

## Parsing Pipeline

```mermaid theme={null}
flowchart TD
    A[Exa Answer Response] --> B[parse_json_from_answer]
    B -->|"Found 5"| F[Add favicons]
    B -->|"< 5"| C[parse_competitors_from_text]
    C -->|"Found 5"| F
    C -->|"< 5"| D[fallback_from_citations]
    D --> F
    F --> G[Return competitors]
```

## Code Location

```
src/website/competitor_research/service.py
# Lines 90-165: fetch_competitors_from_exa()
```
