Overview
The token endpoint is used to exchange an authorization code for access tokens, or to refresh an expired access token using a refresh token.Request Body
Content-Type:application/json
Authorization Code Grant
Must be
authorization_code for code exchangeThe authorization code received from the
/authorize endpointThe PKCE code verifier that was used to generate the code challenge
The same redirect URI used in the authorization request
Your OAuth client ID
Your OAuth client secret
Refresh Token Grant
Must be
refresh_token for token refreshThe refresh token received in a previous token response
Your OAuth client ID
Your OAuth client secret
Response
Success (200 OK)
JWT access token used to authenticate API requests. Valid for 1 hour.
Always
BearerTime in seconds until the access token expires (3600 = 1 hour)
Refresh token used to obtain new access tokens. Valid for 30 days.
Space-separated list of granted scopes
Error (400 / 401)
Error Codes
| Error Code | HTTP Status | Description |
|---|---|---|
unsupported_grant_type | 400 | Grant type must be authorization_code or refresh_token |
invalid_request | 400 | Missing required parameters |
invalid_client | 401 | Invalid client credentials |
invalid_grant | 400 | Invalid, expired, or revoked authorization code/refresh token |
server_error | 500 | Internal server error |
Example Requests
Token Lifecycle
1
Authorization Code Exchange
Exchange the authorization code for initial access and refresh tokens. Authorization codes expire after 10 minutes.
2
Use Access Token
Use the access token to make authenticated API requests. Access tokens are valid for 1 hour.
3
Refresh When Expired
When the access token expires, use the refresh token to get new tokens. Refresh tokens are valid for 30 days.
4
Automatic Rotation
Each refresh generates new access and refresh tokens. The old refresh token is automatically revoked.
Access Token Structure
Access tokens are JWTs (JSON Web Tokens) with the following structure:Header
Payload
| Claim | Description |
|---|---|
sub | Agent ID (subject) |
iss | Issuer (Auth Agent API URL) |
iat | Issued at timestamp |
exp | Expiration timestamp |
client_id | OAuth client ID |
model | AI model used by the agent |
scope | Granted scopes |
Token Storage Best Practices
Server-Side Applications
Server-Side Applications
Store tokens in secure, HTTP-only cookies or server-side sessions. Never expose client secrets in client-side code.
Token Refresh Strategy
Token Refresh Strategy
Implement proactive token refresh before expiration:
Handle Refresh Token Rotation
Handle Refresh Token Rotation
Always update stored tokens after refresh:
Security Considerations
PKCE validation - The code_verifier must match the code_challenge used in the authorization request, or the token exchange will fail.
