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

# Exchange a workload credential

POST https://api.mixlayer.com/v1/workload_identity/token
Content-Type: application/json

Validates an external credential against an active provider and returns a short-lived Mixlayer bearer token.

Reference: https://docs.mixlayer.com/api-reference/platform-api/workload-identity-providers/exchange-workload-identity-token

## Request

### Body (application/json)

This endpoint expects a WorkloadIdentityTokenExchangeRequest.

- `grant_type` (string, required) — RFC 8693 token-exchange grant vocabulary.
- `identity_provider_id` (string, required) — Workload identity provider selected for validation and policy evaluation.
- `subject_token` (string, required) — External OIDC JWT.
- `subject_token_type` (string, required) — External credential type; currently the JWT token type.

## Response

### 200

Short-lived workload access token

- `access_token` (string, required) — Prefixed compact Mixlayer workload JWT.
- `expires_in` (long, required) — Remaining token lifetime in seconds.
- `issued_token_type` (string, required) — OAuth token type describing the issued credential.
- `token_type` (string, required) — Bearer authentication scheme.

## Errors

### 400 Bad Request Error

Invalid exchange request

- `error` (string, required) — Stable OAuth-style error code.
- `error_description` (string, required) — Generic description that does not disclose provider or credential details.

### 413 Content Too Large Error

Exchange request body is too large

- `error` (string, required) — Stable OAuth-style error code.
- `error_description` (string, required) — Generic description that does not disclose provider or credential details.

### 429 Too Many Requests Error

Exchange capacity is temporarily exhausted

- `error` (string, required) — Stable OAuth-style error code.
- `error_description` (string, required) — Generic description that does not disclose provider or credential details.

### 503 Service Unavailable Error

Token exchange is not configured

- `error` (string, required) — Stable OAuth-style error code.
- `error_description` (string, required) — Generic description that does not disclose provider or credential details.

## Examples

**Request**

```json
{
  "grant_type": "string",
  "identity_provider_id": "string",
  "subject_token": "string",
  "subject_token_type": "string"
}
```

**Response**

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

**SDK Code**

```python
import requests

url = "https://api.mixlayer.com/v1/workload_identity/token"

payload = {
    "grant_type": "string",
    "identity_provider_id": "string",
    "subject_token": "string",
    "subject_token_type": "string"
}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript
const url = 'https://api.mixlayer.com/v1/workload_identity/token';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"grant_type":"string","identity_provider_id":"string","subject_token":"string","subject_token_type":"string"}'
};

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"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.mixlayer.com/v1/workload_identity/token"

	payload := strings.NewReader("{\n  \"grant_type\": \"string\",\n  \"identity_provider_id\": \"string\",\n  \"subject_token\": \"string\",\n  \"subject_token_type\": \"string\"\n}")

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

	req.Header.Add("Content-Type", "application/json")

	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://api.mixlayer.com/v1/workload_identity/token")

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

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"grant_type\": \"string\",\n  \"identity_provider_id\": \"string\",\n  \"subject_token\": \"string\",\n  \"subject_token_type\": \"string\"\n}"

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://api.mixlayer.com/v1/workload_identity/token")
  .header("Content-Type", "application/json")
  .body("{\n  \"grant_type\": \"string\",\n  \"identity_provider_id\": \"string\",\n  \"subject_token\": \"string\",\n  \"subject_token_type\": \"string\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.mixlayer.com/v1/workload_identity/token', [
  'body' => '{
  "grant_type": "string",
  "identity_provider_id": "string",
  "subject_token": "string",
  "subject_token_type": "string"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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