# Authentication

For authenticating requests with Stampede, Bearer Tokens are included in the request headers to ensure secure and authorised access. You generate these tokens using OAuth 2.0 client credentials flow. Your requests must include the Bearer Token in the headers like this:

```markup
authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
```

### Generating a `client_id` & `client_secret`

You can generate a `client_id` & `client_secret` by heading to the [Stampede dashboard](https://product.stampede.ai/) > Marketplace > API Keys > Create New API Key.

From there, you'll be able to create a new `client_id` then in return will provide you with a `client_secret`. Keep it safe so it saves the hassle...

### Generating a Bearer Token using OAuth 2.0 Client Credentials

## Generate a Bearer Token

<mark style="color:green;">`POST`</mark> `https://global.stampede.ai/oauth/token`

#### Request Body

| Name                                             | Type   | Description         |
| ------------------------------------------------ | ------ | ------------------- |
| client\_id<mark style="color:red;">\*</mark>     | String |                     |
| client\_secret<mark style="color:red;">\*</mark> | String |                     |
| grant\_type<mark style="color:red;">\*</mark>    | String | client\_credentials |

{% tabs %}
{% tab title="200: OK " %}

```typescript
{
  "access_token": string,
  "expires_in": number,
  "token_type": "Bearer",
  "scope": "ALL:ALL"
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```typescript
{
    "error": string,
    "error_description": string
}
```

{% endtab %}
{% endtabs %}

### Examples

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

```url
curl --location 'https://global.stampede.ai/oauth/token' \
--header 'Content-Type: application/json' \
--data '{
    "client_id": "ai.stampede.marketplace.example",
    "client_secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "grant_type": "client_credentials"
}'
```

{% endtab %}

{% tab title="NodeJs - Axios" %}

```javascript
const axios = require('axios');
let data = JSON.stringify({
  "client_id": "ai.stampede.marketplace.example",
  "client_secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "grant_type": "client_credentials"
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://global.stampede.ai/oauth/token',
  headers: { 
    'Content-Type': 'application/json'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});
```

{% endtab %}

{% tab title="PHP - Guzzle" %}

```php
<?php
$client = new Client();
$headers = [
  'Content-Type' => 'application/json'
];
$body = '{
  "client_id": "ai.stampede.marketplace.example",
  "client_secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "grant_type": "client_credentials"
}';
$request = new Request('POST', 'https://global.stampede.ai/oauth/token', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();

```

{% endtab %}

{% tab title="Python - http.client" %}

```python
import http.client
import json

conn = http.client.HTTPSConnection("global.stampede.ai")
payload = json.dumps({
  "client_id": "ai.stampede.marketplace.example",
  "client_secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "grant_type": "client_credentials"
})
headers = {
  'Content-Type': 'application/json'
}
conn.request("POST", "/oauth/token", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: 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://developer.stampede.ai/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.
