> For the complete documentation index, see [llms.txt](https://docs.pex.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pex.com/search/api-documentation/authentication.md).

# Authentication

### Authentication

The API uses OAuth 2.0 Client Credentials. You will need a `CLIENT_ID` and `CLIENT_SECRET`.

The generated access token must be included in every request to the Search API.

The access token is valid for 2 hours. Clients should reuse the same token for multiple requests until it expires, rather than requesting a new token for each call. When the token expires, request a new one using the same client credentials.

#### Token Endpoint

```
POST https://api.ae.pex.com/oauth2/token
```

#### Authentication Method

* Auth: HTTP Basic Auth
* Body: `grant_type=client_credentials`

#### Examples

{% tabs %}
{% tab title="Python" %}

```python
import requests

CLIENT_ID = "YOUR_CLIENT_ID"
CLIENT_SECRET = "YOUR_CLIENT_SECRET"

response = requests.post(
    "https://api.ae.pex.com/oauth2/token",
    auth=(CLIENT_ID, CLIENT_SECRET),
    data={
        "grant_type": "client_credentials",
    },
)

response.raise_for_status()

access_token = response.json()["access_token"]

print(access_token)
```

{% endtab %}

{% tab title="Bash" %}

```bash
CLIENT_ID="YOUR_CLIENT_ID"
CLIENT_SECRET="YOUR_CLIENT_SECRET"

ACCESS_TOKEN=$(curl -s \
  -u "${CLIENT_ID}:${CLIENT_SECRET}" \
  -d "grant_type=client_credentials" \
  "https://api.ae.pex.com/oauth2/token" | jq -r '.access_token')

echo "${ACCESS_TOKEN}"
```

{% endtab %}
{% endtabs %}

#### Response

A successful authentication request returns an OAuth access token.

{% tabs %}
{% tab title="JSON" %}

```json
{
  "access_token": "example_access_token",
  "token_type": "Bearer",
  "expires_in": 7200
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pex.com/search/api-documentation/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
