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

# How to use the Public API?

Our public API is documented with Swagger and can be accessed at [https://api.keywordinsights.ai/apidocs](https://api.keywordinsights.ai/apidocs/).

<Warning>
  **Bearer token authentication is deprecated.** We recommend switching to API keys, which are simpler to set up, don't expire, and don't require you to handle token refresh. See [API Key Authentication](/api/api-key-authentication) to get started. Bearer tokens will continue to work for now, but may be removed in a future update.
</Warning>

### Prerequisites to use the public API

You need to have a valid **Keyword Insights** subscription in order to use the public API.

Before using the public API, you must acquire a **Bearer token** for authentication so that our servers can verify who you are and that you have permission to use the API.

### How to use the interactive public API documentation

To use the Swagger UI interactively, you must first be authenticated.\
Follow the instructions below to generate a **Bearer token**.

Once you are authenticated, you can **Try it out** on any endpoint by providing your Bearer token and the required parameters.

### Authenticate and retrieve a Bearer token (email and password)

This approach is for users who signed up with an email and password (not via Google Sign In).\
If you signed up with **Create with Google**, use the Google Sign In approach in the next section instead:\
[How to authenticate with the public API and retrieve a bearer token? (Google Sign In Approach)](how-to-use-the-public-api.mdx#how-to-authenticate-with-the-public-api-and-retrieve-a-bearer-token-google-sign-in-approach)

1. Open the [API documentation](https://api.keywordinsights.ai/apidocs/), scroll to the bottom of the page, and locate the **Authentication** section.

<img src="https://mintcdn.com/snippetdigital/jBGkmInQA6GjnN58/images/image.png?fit=max&auto=format&n=jBGkmInQA6GjnN58&q=85&s=7d406ef5b6673dd9684d731907ca6621" alt="Authentication section in Keyword Insights Swagger public API" width="2860" height="218" data-path="images/image.png" />

Alternatively, you can go directly to the authentication endpoint using this link:\
[Authentication → /authentication/login](https://api.keywordinsights.ai/apidocs/#/Authentication/post_authentication_login_)

You should now see the authentication request details, including a **Try it out** button.

<img src="https://mintcdn.com/snippetdigital/jBGkmInQA6GjnN58/images/image%20(2).png?fit=max&auto=format&n=jBGkmInQA6GjnN58&q=85&s=731720274aaa8cf14d7962efcd1fe164" alt="Click the Try it out button to get started using the Keyword Insights public API" width="2152" height="1617" data-path="images/image (2).png" />

2. After clicking **Try it out**, the request body field becomes editable.
   1. Enter your valid email address and password, exactly as you would on `app.keywordinsights.ai`.
   2. Click the large blue **Execute** button below the text field.

<img src="https://mintcdn.com/snippetdigital/jBGkmInQA6GjnN58/images/image%20(3).png?fit=max&auto=format&n=jBGkmInQA6GjnN58&q=85&s=b8525666badf934de7ff91eb0a92b541" alt="Enter email and password, then click Execute" width="2126" height="1118" data-path="images/image (3).png" />

If your email and password are correct, you should see a **200** response code and a JSON response object containing a `result` object.

3. In the response, copy the value of the `access_token`.\
   In the example below, the token starts with `eyJ0....` and ends with `...Mokg`. You will need this token in the next step.

<img src="https://mintcdn.com/snippetdigital/jBGkmInQA6GjnN58/images/image%20(5).png?fit=max&auto=format&n=jBGkmInQA6GjnN58&q=85&s=6916d7b02176981c15b06e9e61074119" alt="Viewing the access token upon a successful authentication request" width="2134" height="1134" data-path="images/image (5).png" />

4. In a text editor of your choice, paste the copied access token and prepend the word `Bearer` (with a capital **B**), separated by a single space.\
   Your complete string should look similar to:

```
Bearer eyJ0e..rest_of_the_token...4AnRMokg
```

This full string (including the word `Bearer`) is what you will use as the **Authorization** header for any authenticated API request.\
Some endpoints also require additional arguments such as `order_id`, which you can usually find in the URL of the respective page in the application.

5. Validate your Bearer token using the steps in the section\
   [Validate your Bearer Token](how-to-use-the-public-api.mdx#validate-your-bearer-token).

### Authenticate and retrieve a Bearer token (Google Sign In)

Use this approach if you signed up using **Create with Google** instead of creating a password during sign up.

If you signed up manually with an email and password, use the previous section instead:\
[How to authenticate with the public API and retrieve a bearer token? (Email and password approach)](how-to-use-the-public-api.mdx#how-to-authenticate-with-the-public-api-and-retrieve-a-bearer-token-email-and-password-approach)

1. In your browser of choice (Chrome in this example), open a new tab and open the **Network** tab in the developer tools.

<img src="https://mintcdn.com/snippetdigital/jBGkmInQA6GjnN58/images/image%20(9).png?fit=max&auto=format&n=jBGkmInQA6GjnN58&q=85&s=d226882898d6b21e53b338221c6a7d87" alt="Opening the developer tools in Google Chrome" width="3360" height="2100" data-path="images/image (9).png" />

<img src="https://mintcdn.com/snippetdigital/jBGkmInQA6GjnN58/images/image%20(10).png?fit=max&auto=format&n=jBGkmInQA6GjnN58&q=85&s=39d0fc655ea347ecc49aaba9a09e61f3" alt="Opening the Network tab in the Chrome developer tools" width="3360" height="1928" data-path="images/image (10).png" />

2. In the address bar, navigate to [https://app.keywordinsights.ai](https://app.keywordinsights.ai/).\
   Before logging in, click the **clear** button in the Network tab so that you can easily see only the upcoming requests.

<img src="https://mintcdn.com/snippetdigital/jBGkmInQA6GjnN58/images/image%20(11).png?fit=max&auto=format&n=jBGkmInQA6GjnN58&q=85&s=3a736c90c3062e851cdd1f953e902028" alt="Clearing the Network tab to more easily inspect the next requests" width="3360" height="1928" data-path="images/image (11).png" />

3. Click **LOG IN WITH GOOGLE** and follow the prompts in the pop-up window as you normally would when signing in to the application.

4. After you are logged in, go back to the Network tab and locate a successful request (for example, the `/user` request – but any authenticated request will work).
   * Select the request.
   * In the right-hand panel, make sure the **Headers** tab is selected.
   * Scroll down until you find the **Authorization** header.
   * Copy the entire value of the Authorization header, including the word `Bearer`.

<img src="https://mintcdn.com/snippetdigital/jBGkmInQA6GjnN58/images/image%20(12).png?fit=max&auto=format&n=jBGkmInQA6GjnN58&q=85&s=741c60d436d9079b504c771f49be99be" alt="Copying the Bearer token from an authenticated request in the Network tab" width="3360" height="1928" data-path="images/image (12).png" />

5. Validate your Bearer token using the steps in\
   [Validate your Bearer Token](how-to-use-the-public-api.mdx#validate-your-bearer-token).

### Validate your Bearer Token

To confirm that your **Bearer token** works correctly, you can call the **User** endpoint in Swagger.

1. In the Swagger UI, navigate to the **User** endpoint and click **Try it out** to make the input fields editable.
2. Paste the full Bearer token string (including the word `Bearer`) into the appropriate field.
3. Click the large blue **Execute** button.

<img src="https://mintcdn.com/snippetdigital/jBGkmInQA6GjnN58/images/image%20(6).png?fit=max&auto=format&n=jBGkmInQA6GjnN58&q=85&s=8623e59bd1bdc2c564c8a01464a8a4fc" alt="Entering the Bearer token to validate it via the User endpoint" width="2173" height="546" data-path="images/image (6).png" />

<img src="https://mintcdn.com/snippetdigital/jBGkmInQA6GjnN58/images/image%20(7).png?fit=max&auto=format&n=jBGkmInQA6GjnN58&q=85&s=1a931cfe215e9d6199c4c7c2943711d8" alt="Executing the request to validate the Bearer token" width="2153" height="595" data-path="images/image (7).png" />

4. If the Bearer token is valid, you should see a **200** response code and your user object in the response body.

<img src="https://mintcdn.com/snippetdigital/jBGkmInQA6GjnN58/images/image%20(8).png?fit=max&auto=format&n=jBGkmInQA6GjnN58&q=85&s=d5463c25be2ec9ecb22dc0f986f59a43" alt="Successful response when validating the Bearer token" width="2164" height="1568" data-path="images/image (8).png" />

**Congratulations! You have successfully authenticated with our public API. You can now call any endpoint documented in the API reference.**

<details>
  <summary>How much is the API and how is it calculated?</summary>

  The API is available for **Professional** and **Premium** subscriptions.\
  For clustering, we provide a calculation endpoint at\
  [https://dev.api.keywordinsights.ai/apidocs](https://dev.api.keywordinsights.ai/apidocs/#/)\
  that tells you how many credits are required based on your settings.\
  The API itself has **no additional pricing** beyond your subscription and credit usage.
</details>
