curl --request POST \
--url https://openrouter.ai/api/v1/oauth/token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data federation_policy_id=4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b \
--data grant_type=urn:ietf:params:oauth:grant-type:token-exchange \
--data 'subject_token=<jwt from your identity provider>' \
--data subject_token_type=urn:ietf:params:oauth:token-type:jwtimport requests
url = "https://openrouter.ai/api/v1/oauth/token"
payload = {
"federation_policy_id": "4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b",
"grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
"subject_token": "<jwt from your identity provider>",
"subject_token_type": "urn:ietf:params:oauth:token-type:jwt"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/x-www-form-urlencoded"
}
response = requests.post(url, data=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
Authorization: 'Bearer <token>',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
federation_policy_id: '4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b',
grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',
subject_token: '<jwt from your identity provider>',
subject_token_type: 'urn:ietf:params:oauth:token-type:jwt'
})
};
fetch('https://openrouter.ai/api/v1/oauth/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://openrouter.ai/api/v1/oauth/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "federation_policy_id=4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&subject_token=%3Cjwt%20from%20your%20identity%20provider%3E&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/x-www-form-urlencoded"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://openrouter.ai/api/v1/oauth/token"
payload := strings.NewReader("federation_policy_id=4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&subject_token=%3Cjwt%20from%20your%20identity%20provider%3E&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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(string(body))
}HttpResponse<String> response = Unirest.post("https://openrouter.ai/api/v1/oauth/token")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/x-www-form-urlencoded")
.body("federation_policy_id=4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&subject_token=%3Cjwt%20from%20your%20identity%20provider%3E&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt")
.asString();require 'uri'
require 'net/http'
url = URI("https://openrouter.ai/api/v1/oauth/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/x-www-form-urlencoded'
request.body = "federation_policy_id=4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&subject_token=%3Cjwt%20from%20your%20identity%20provider%3E&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt"
response = http.request(request)
puts response.read_body{
"access_token": "<short-lived openrouter access token jwt>",
"expires_in": 900,
"issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
"scope": "inference",
"token_type": "Bearer"
}{
"error": "invalid_grant",
"error_description": "The subject token was not accepted."
}{
"error": "invalid_grant",
"error_description": "The subject token was not accepted."
}{
"error": "invalid_grant",
"error_description": "The subject token was not accepted."
}{
"error": "invalid_grant",
"error_description": "The subject token was not accepted."
}Exchange a workload identity token
RFC 8693 token exchange. Presents a JWT from an issuer your organization trusts (Settings → Workload identity) and receives a short-lived OpenRouter access token that acts as the API key the matching federation policy targets.
curl --request POST \
--url https://openrouter.ai/api/v1/oauth/token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data federation_policy_id=4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b \
--data grant_type=urn:ietf:params:oauth:grant-type:token-exchange \
--data 'subject_token=<jwt from your identity provider>' \
--data subject_token_type=urn:ietf:params:oauth:token-type:jwtimport requests
url = "https://openrouter.ai/api/v1/oauth/token"
payload = {
"federation_policy_id": "4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b",
"grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
"subject_token": "<jwt from your identity provider>",
"subject_token_type": "urn:ietf:params:oauth:token-type:jwt"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/x-www-form-urlencoded"
}
response = requests.post(url, data=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
Authorization: 'Bearer <token>',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
federation_policy_id: '4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b',
grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',
subject_token: '<jwt from your identity provider>',
subject_token_type: 'urn:ietf:params:oauth:token-type:jwt'
})
};
fetch('https://openrouter.ai/api/v1/oauth/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://openrouter.ai/api/v1/oauth/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "federation_policy_id=4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&subject_token=%3Cjwt%20from%20your%20identity%20provider%3E&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/x-www-form-urlencoded"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://openrouter.ai/api/v1/oauth/token"
payload := strings.NewReader("federation_policy_id=4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&subject_token=%3Cjwt%20from%20your%20identity%20provider%3E&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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(string(body))
}HttpResponse<String> response = Unirest.post("https://openrouter.ai/api/v1/oauth/token")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/x-www-form-urlencoded")
.body("federation_policy_id=4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&subject_token=%3Cjwt%20from%20your%20identity%20provider%3E&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt")
.asString();require 'uri'
require 'net/http'
url = URI("https://openrouter.ai/api/v1/oauth/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/x-www-form-urlencoded'
request.body = "federation_policy_id=4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&subject_token=%3Cjwt%20from%20your%20identity%20provider%3E&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt"
response = http.request(request)
puts response.read_body{
"access_token": "<short-lived openrouter access token jwt>",
"expires_in": 900,
"issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
"scope": "inference",
"token_type": "Bearer"
}{
"error": "invalid_grant",
"error_description": "The subject token was not accepted."
}{
"error": "invalid_grant",
"error_description": "The subject token was not accepted."
}{
"error": "invalid_grant",
"error_description": "The subject token was not accepted."
}{
"error": "invalid_grant",
"error_description": "The subject token was not accepted."
}Authorizations
API key as bearer token in Authorization header
Body
RFC 8693 token exchange request body (application/x-www-form-urlencoded).
The federation policy to evaluate, from Settings → Workload identity. Binds the exchange to one organization.
"4b2f7d1e-8c3a-4e5f-9a6b-1c2d3e4f5a6b"
Must be urn:ietf:params:oauth:grant-type:token-exchange.
urn:ietf:params:oauth:grant-type:token-exchange "urn:ietf:params:oauth:grant-type:token-exchange"
The JWT issued by your identity provider.
1 - 16384"<jwt from your identity provider>"
Must be urn:ietf:params:oauth:token-type:jwt.
urn:ietf:params:oauth:token-type:jwt "urn:ietf:params:oauth:token-type:jwt"
Optional; when present must be urn:ietf:params:oauth:token-type:access_token.
urn:ietf:params:oauth:token-type:access_token "urn:ietf:params:oauth:token-type:access_token"
Optional; only inference is available.
inference "inference"
Response
Access token issued
RFC 8693 token exchange response.
A short-lived JWT to send as Authorization: Bearer to the inference API.
"<short-lived openrouter access token jwt>"
Seconds until the access token expires: at most 15 minutes, and never later than the subject token expires.
900
urn:ietf:params:oauth:token-type:access_token "urn:ietf:params:oauth:token-type:access_token"
"inference"
Bearer "Bearer"