> This page is for Alfa (Preview).

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.alfa.boosted.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.alfa.boosted.ai/_mcp/server.

# OAuth 2.0 Token Exchange

POST https://sandbox.api.boosted.ai/oauth2/token
Content-Type: application/x-www-form-urlencoded

Exchanges a partner-issued JWT for a Boosted access token. Partners authenticate using client credentials (client_id and client_secret) and provide a signed JWT in the request body. The JWT is validated and exchanged for a Boosted token with the requested scope.

Reference: https://docs.alfa.boosted.ai/alfa-preview/account-management-api/reference/o-auth/token-exchange

## Request

### Body (application/x-www-form-urlencoded)

This endpoint expects an object.

- `grant_type` (string, required) — Grant type (must be 'urn:ietf:params:oauth:grant-type:token-exchange')
- `subject_token` (string, required) — The partner-issued JWT to exchange
- `subject_token_type` (string, required) — Token type (must be 'urn:ietf:params:oauth:token-type:jwt')
- `client_id` (string, required) — Partner client ID
- `client_secret` (string, required) — Partner client secret
- `scope` (string, optional) — Requested scope (e.g., 'thread', 'account-management')

## Response

### 200

OK

- `access_token` (string, optional)
- `expires_in` (integer, optional)
- `issued_token_type` (string, optional)
- `scope` (string, optional)
- `token_type` (string, optional)

## Errors

### 400 Bad Request Error

Bad Request - Invalid grant type, token type, or malformed request

- `map from string to string`

### 401 Unauthorized Error

Unauthorized - Invalid client credentials or JWT

- `map from string to string`

## Examples

**Request**

```json
{
  "grant_type": "string",
  "subject_token": "string",
  "subject_token_type": "string",
  "client_id": "string",
  "client_secret": "string"
}
```

**Response**

```json
{
  "access_token": "string",
  "expires_in": 1,
  "issued_token_type": "string",
  "scope": "string",
  "token_type": "string"
}
```

**SDK Code**

```python
import requests

url = "https://sandbox.api.boosted.ai/oauth2/token"

payload = ""
headers = {"Content-Type": "application/x-www-form-urlencoded"}

response = requests.post(url, data=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.api.boosted.ai/oauth2/token';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  body: new URLSearchParams('')
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.api.boosted.ai/oauth2/token"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.api.boosted.ai/oauth2/token")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/x-www-form-urlencoded'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.api.boosted.ai/oauth2/token")
  .header("Content-Type", "application/x-www-form-urlencoded")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.api.boosted.ai/oauth2/token', [
  'form_params' => null,
  'headers' => [
    'Content-Type' => 'application/x-www-form-urlencoded',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.api.boosted.ai/oauth2/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/x-www-form-urlencoded"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.api.boosted.ai/oauth2/token")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```