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

# Get an agent access token

POST https://api.runtype.com/v1/identity/token
Content-Type: application/x-www-form-urlencoded

OAuth 2.0 token endpoint for agents running outside Runtype. An external agent authenticates as the OAuth client (`private_key_jwt`, `client_secret_basic` or `client_secret_post`) and gets a short-lived RFC 9068 access token whose `sub` is `agent:<agentId>` and whose `aud` is the requested resource, when the agent audience policy allows that resource. Errors follow RFC 6749 §5.2. Responses are never cached.

Reference: https://docs.runtype.com/api-reference/runtype-api/identity-integrations/get-an-agent-access-token

## Servers

- `https://api.runtype.com` (Production, default)
- `https://api.runtype-staging.com` (Staging)

## Request

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

This endpoint expects an object.

- `grant_type` (enum, required) — Always `client_credentials`. Token exchange returns `unsupported_grant_type`.
  - Allowed values: `client_credentials`
- `resource` (string, required) — The canonical resource URI (RFC 8707) the token is for, for example `https://mcp.example.com/mcp`. It must be on the agent audience policy for the principal grant.
- `actor_token` (string, optional) — Not accepted; the actor is the authenticated client.
- `audience` (string, optional) — Not accepted; name the target with `resource`.
- `client_assertion` (string, optional) — A JWT signed with a registered key (`private_key_jwt`): `iss` and `sub` are the agent ID, `aud` is the agents issuer, `jti` is unique, and `exp - iat` is at most 300 seconds.
- `client_assertion_type` (enum, optional)
  - Allowed values: `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
- `client_id` (string, optional) — The agent ID. Required with `client_secret`; optional with a client assertion, whose `sub` names the agent.
- `client_secret` (string, optional) — An `rt_agent_sk_` client secret (`client_secret_post`). Prefer HTTP Basic or a client assertion.
- `scope` (string, optional) — Space-separated scopes; each must be allowed by the policy entry for `resource`.

## Response

### 200

The issued token.

- `access_token` (string, required) — An RFC 9068 `at+jwt` signed with the keys at `/.well-known/jwks.json`.
- `expires_in` (integer, required) — Seconds until the token expires; at most 300.
- `issued_token_type` (enum, required)
  - Allowed values: `urn:ietf:params:oauth:token-type:access_token`
- `token_type` (enum, required)
  - Allowed values: `Bearer`
- `scope` (string, optional) — The granted scopes, when any were requested and allowed.

## Errors

### 400 Bad Request Error

The request was refused.

- `error` (enum, required)
  - Allowed values: `invalid_request`, `invalid_client`, `invalid_grant`, `unauthorized_client`, `unsupported_grant_type`, `invalid_target`, `invalid_scope`, `temporarily_unavailable`, `server_error`
- `error_description` (string, optional)

### 401 Unauthorized Error

Client authentication failed.

- `error` (enum, required)
  - Allowed values: `invalid_request`, `invalid_client`, `invalid_grant`, `unauthorized_client`, `unsupported_grant_type`, `invalid_target`, `invalid_scope`, `temporarily_unavailable`, `server_error`
- `error_description` (string, optional)

### 429 Too Many Requests Error

Too many token requests.

- `error` (enum, required)
  - Allowed values: `invalid_request`, `invalid_client`, `invalid_grant`, `unauthorized_client`, `unsupported_grant_type`, `invalid_target`, `invalid_scope`, `temporarily_unavailable`, `server_error`
- `error_description` (string, optional)

### 500 Internal Server Error

No token was issued.

- `error` (enum, required)
  - Allowed values: `invalid_request`, `invalid_client`, `invalid_grant`, `unauthorized_client`, `unsupported_grant_type`, `invalid_target`, `invalid_scope`, `temporarily_unavailable`, `server_error`
- `error_description` (string, optional)

### 503 Service Unavailable Error

Issuance is temporarily unavailable.

- `error` (enum, required)
  - Allowed values: `invalid_request`, `invalid_client`, `invalid_grant`, `unauthorized_client`, `unsupported_grant_type`, `invalid_target`, `invalid_scope`, `temporarily_unavailable`, `server_error`
- `error_description` (string, optional)

## Examples

**Request**

```json
{
  "grant_type": "client_credentials",
  "resource": "string"
}
```

**Response**

```json
{
  "access_token": "string",
  "expires_in": 1,
  "issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
  "token_type": "Bearer",
  "scope": "string"
}
```

**SDK Code**

```python
import requests

url = "https://api.runtype.com/v1/identity/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://api.runtype.com/v1/identity/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://api.runtype.com/v1/identity/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://api.runtype.com/v1/identity/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://api.runtype.com/v1/identity/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://api.runtype.com/v1/identity/token', [
  'form_params' => null,
  'headers' => [
    'Content-Type' => 'application/x-www-form-urlencoded',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.runtype.com/v1/identity/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://api.runtype.com/v1/identity/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()
```