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

# Authentication

> How to authenticate requests to News API.

News API uses API key authentication. Include your API key in the `x-api-token`
header on every request:

```http theme={null}
x-api-token: YOUR_API_KEY
```

An invalid or missing key returns a `401 Unauthorized` response. See
[Errors](/news-api/api-reference/errors) for details.

## Authentication example

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://v3-api.newscatcherapi.com/api/search" \
    -H "x-api-token: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "q": "renewable energy",
      "lang": "en",
      "page_size": 1
    }'
  ```

  ```python Python theme={null}
  from newscatcher import NewscatcherApi

  client = NewscatcherApi(api_key="YOUR_API_KEY")

  response = client.search.post(
      q="renewable energy",
      lang="en",
      page_size=1,
  )

  print(response.articles[0].title)
  ```

  ```typescript TypeScript theme={null}
  import { NewscatcherApiClient } from "newscatcher-sdk";

  const client = new NewscatcherApiClient({ apiKey: "YOUR_API_KEY" });

  const response = await client.search.post({
    q: "renewable energy",
    lang: "en",
    pageSize: 1,
  });

  console.log(response.articles?.[0]?.title);
  ```

  ```java Java theme={null}
  import com.newscatcher.api.NewscatcherApiClient;
  import com.newscatcher.api.resources.search.requests.PostSearchRequest;

  NewscatcherApiClient client = NewscatcherApiClient.builder()
      .apiKey("YOUR_API_KEY")
      .build();

  var response = client.search().post(
      PostSearchRequest.builder()
          .q("renewable energy")
          .lang("en")
          .pageSize(1)
          .build()
  );

  System.out.println(response.getArticles().get(0).getTitle());
  ```
</CodeGroup>

## Security best practices

Follow these practices to keep your API key secure:

* Never expose your API key in client-side code, public repositories, or
  anywhere accessible to unauthorized parties.
* Store your API key in environment variables or a secrets manager, not in
  source code.
* Rotate your API key periodically.
* Monitor your usage to detect unauthorized access early.
* If you suspect your key has been compromised, contact
  [support](https://support-sign-in.newscatcherapi.com/) immediately to have it
  revoked and replaced.

## See also

For related topics, see the following resources:

* [HTTP headers](/news-api/api-reference/http-headers)
* [Rate limits](/news-api/api-reference/rate-limits)
* [Subscription plans](/news-api/get-started/subscription-plans)
