> ## Documentation Index
> Fetch the complete documentation index at: https://test-62a57ffd.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Spellcheck

> Intelligent spell checking to improve query quality and help users find what they're looking for

## Overview

Brave Search Spellcheck API provides advanced spell checking capabilities for search queries. It analyzes queries to detect spelling errors and suggests corrected alternatives, helping users get better search results even when they make typos or spelling mistakes.

## Key Features

<CardGroup cols={2}>
  <Card title="Query Correction" icon="spell-check">
    Automatically detect and correct spelling errors in search queries
  </Card>

  <Card title="Contextual Suggestions" icon="wand-magic-sparkles">
    Intelligent corrections based on query context and search patterns
  </Card>

  <Card title="Fast Response" icon="bolt">
    Low-latency spell checking for real-time query processing
  </Card>

  <Card title="Language Support" icon="language">
    Multi-language spell checking with country-specific corrections
  </Card>
</CardGroup>

## API Reference

<Card title="Spellcheck API Documentation" icon="code" href="/api-reference/spellcheck/search">
  View the complete API reference, including endpoints, parameters, and example
  requests
</Card>

## Use Cases

Spellcheck API is perfect for:

* **Search Applications**: Improve user experience by correcting typos before searching
* **Query Suggestions**: Offer spelling corrections in search interfaces
* **Data Quality**: Clean and normalize user-generated queries
* **Autocorrect**: Implement "Did you mean?" functionality
* **Query Analysis**: Identify and track common misspellings

## Endpoint

Brave Spellcheck API is available at the following endpoint:

```bash theme={null}
https://api.search.brave.com/res/v1/spellcheck/search
```

<Note>
  To try the API on a Free plan, you'll still need to subscribe — you simply
  won't be charged. Once subscribed, you can get an API key in the [API
  Keys](https://api-dashboard.search.brave.com/app/keys) section.
</Note>

## Getting Started

Get started immediately with a simple cURL request:

```bash theme={null}
curl -s --compressed "https://api.search.brave.com/res/v1/spellcheck/search?q=helo&country=US" \
  -H "Accept: application/json" \
  -H "Accept-Encoding: gzip" \
  -H "X-Subscription-Token: <YOUR_API_KEY>"
```

### Example Response

```json theme={null}
{
  "type": "spellcheck",
  "query": {
    "original": "helo"
  },
  "corrected": {
    "query": "hello",
    "altered": true
  }
}
```

## Common Examples

### No Correction Needed

When the query is already spelled correctly:

```bash theme={null}
curl -s --compressed "https://api.search.brave.com/res/v1/spellcheck/search?q=hello&country=US" \
  -H "Accept: application/json" \
  -H "Accept-Encoding: gzip" \
  -H "X-Subscription-Token: <YOUR_API_KEY>"
```

Response:

```json theme={null}
{
  "type": "spellcheck",
  "query": {
    "original": "hello"
  },
  "corrected": {
    "query": "hello",
    "altered": false
  }
}
```

### Multi-word Correction

The API handles corrections in multi-word queries:

```bash theme={null}
curl -s --compressed "https://api.search.brave.com/res/v1/spellcheck/search?q=articifial+inteligence&country=US" \
  -H "Accept: application/json" \
  -H "Accept-Encoding: gzip" \
  -H "X-Subscription-Token: <YOUR_API_KEY>"
```

Response:

```json theme={null}
{
  "type": "spellcheck",
  "query": {
    "original": "articifial inteligence"
  },
  "corrected": {
    "query": "artificial intelligence",
    "altered": true
  }
}
```

## Integration Examples

### JavaScript/TypeScript

```javascript theme={null}
async function checkSpelling(query, country = "US") {
  const params = new URLSearchParams({
    q: query,
    country: country,
  });

  const response = await fetch(
    `https://api.search.brave.com/res/v1/spellcheck/search?${params}`,
    {
      headers: {
        Accept: "application/json",
        "Accept-Encoding": "gzip",
        "X-Subscription-Token": "YOUR_API_KEY",
      },
    }
  );

  return await response.json();
}

// Usage
const result = await checkSpelling("helo world");
if (result.corrected.altered) {
  console.log(`Did you mean: ${result.corrected.query}?`);
}
```

### Python

```python theme={null}
import requests

def check_spelling(query: str, country: str = "US"):
    url = "https://api.search.brave.com/res/v1/spellcheck/search"

    headers = {
        "Accept": "application/json",
        "Accept-Encoding": "gzip",
        "X-Subscription-Token": "YOUR_API_KEY"
    }

    params = {
        "q": query,
        "country": country
    }

    response = requests.get(url, headers=headers, params=params)
    return response.json()

# Usage
result = check_spelling("helo world")
if result["corrected"]["altered"]:
    print(f"Did you mean: {result['corrected']['query']}?")
```

## Best Practices

### User Experience

* **Show Suggestions Gracefully**: Display "Did you mean?" suggestions without forcing corrections
* **Preserve User Intent**: Allow users to search for their original query if desired
* **Highlight Differences**: Visually indicate which parts of the query were corrected

### Performance Optimization

* **Debounce Requests**: Implement debouncing (e.g., 200-300ms) to avoid excessive API calls
* **Cache Results**: Cache spellcheck results for frequently typed queries
* **Async Loading**: Check spelling asynchronously without blocking user input

### Integration Patterns

```javascript theme={null}
// Debounced spellcheck implementation
function debounce(func, wait) {
  let timeout;
  return function executedFunction(...args) {
    const later = () => {
      clearTimeout(timeout);
      func(...args);
    };
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
  };
}

const debouncedSpellcheck = debounce(async (query) => {
  const result = await checkSpelling(query);
  if (result.corrected.altered) {
    // Show correction suggestion
    showSuggestion(result.corrected.query);
  }
}, 300);

// Call on input change
inputElement.addEventListener("input", (e) => {
  debouncedSpellcheck(e.target.value);
});
```

### Rate Limiting

* Implement client-side throttling to avoid hitting API rate limits
* Consider combining spellcheck with other search operations
* Monitor your API usage and adjust debounce timings accordingly

## Changelog

This changelog outlines all significant changes to the Brave Search Spellcheck API in chronological order.

### 2023-01-01

* Initial launch of Brave Search Spellcheck API
* Support for multi-language spell checking
* Context-aware query corrections
