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

# Authentication

> Learn how to authenticate with the ScrapeLLM API using your API key, manage keys securely, and handle authentication errors.

The ScrapeLLM API uses API key authentication. Include your key in every request using the `X-API-Key` header or the `api_key` query parameter.

## Getting your API key

Sign up at [scrapellm.com/signup](https://scrapellm.com/signup) - 1,500 free credits, no credit card required.

Manage your API keys from the [dashboard](https://scrapellm.com/dashboard). Once you have your key:

1. **Store it securely** - treat it like a password
2. **Never expose it** in client-side code or public repositories

<Warning>
  Never expose your API key in client-side JavaScript, public repositories, or
  share it with unauthorised users.
</Warning>

## Using your API key

### Method 1: X-API-Key header (recommended)

```
X-API-Key: YOUR_API_KEY
```

### Method 2: api\_key query parameter

```
?api_key=YOUR_API_KEY
```

### Example requests

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://api.scrapellm.com/scrapers/chatgpt" \
    -H "X-API-Key: YOUR_API_KEY" \
    -G \
    --data-urlencode "prompt=What brands do marketers recommend?"
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      "https://api.scrapellm.com/scrapers/chatgpt",
      headers={"X-API-Key": "YOUR_API_KEY"},
      params={"prompt": "What brands do marketers recommend?"}
  )
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    "https://api.scrapellm.com/scrapers/chatgpt?prompt=What+brands+do+marketers+recommend%3F",
    { headers: { "X-API-Key": "YOUR_API_KEY" } }
  );
  ```

  ```go Go theme={null}
  req, _ := http.NewRequest("GET", "https://api.scrapellm.com/scrapers/chatgpt", nil)
  req.Header.Add("X-API-Key", "YOUR_API_KEY")
  q := req.URL.Query()
  q.Add("prompt", "What brands do marketers recommend?")
  req.URL.RawQuery = q.Encode()
  resp, _ := http.DefaultClient.Do(req)
  ```
</CodeGroup>

## Authentication errors

If authentication fails, you'll receive a `401 Unauthorized` response:

```json theme={null}
{
  "detail": "Missing API key. Pass your key in the X-API-Key header or as ?api_key= in the URL."
}
```

Common authentication issues:

* **Missing key**: No `X-API-Key` header and no `api_key` query param present
* **Invalid key**: The key doesn't match any active key in the database
* **Credit limit**: Your account has no remaining credits (returns `429`)

## Environment variables

Store your API key in environment variables - never hard-code it:

<CodeGroup>
  ```bash .env theme={null}
  SCRAPELLM_API_KEY=your_api_key_here
  ```

  ```python Python theme={null}
  import os
  api_key = os.getenv("SCRAPELLM_API_KEY")
  ```

  ```javascript Node.js theme={null}
  const apiKey = process.env.SCRAPELLM_API_KEY;
  ```

  ```go Go theme={null}
  apiKey := os.Getenv("SCRAPELLM_API_KEY")
  ```
</CodeGroup>

## API key management

### Creating new keys

Create and manage keys from the [dashboard](https://scrapellm.com/dashboard). Consider separate keys for different environments:

* **Production** - your live application
* **Development** - local development and testing
* **CI/CD** - automated testing pipelines

### Revoking keys

If a key is compromised, revoke it immediately from the dashboard. The old key stops working instantly.

## Need help?

If you're having trouble with authentication, contact [hello@scrapellm.com](mailto:hello@scrapellm.com).
