Skip to content

HTTP API

RTC Agent’s HTTP API provides 3 OAuth2 endpoints for user authentication and token management. The entire flow follows the standard OAuth2 authorization code pattern, compatible with common Providers like GitHub and Google.

💡 Design note: The frontend (F-C) calls /oauth2/authorize to get the redirect URL, then navigates the user to the OAuth2 Provider’s authorization page. After authorization is complete, the Provider calls back to the frontend, which then calls /oauth2/token to complete the token exchange.

EndpointMethodFunctionWhen Called
/oauth2/authorizeGETGet authorization redirect URLUser clicks login
/oauth2/tokenPOSTExchange authorization code for tokensAfter authorization callback
/oauth2/refreshPOSTRefresh access_tokenWhen token is about to expire

Get the redirect URL for the OAuth2 authorization page. The frontend uses this URL to navigate the user to the Provider’s authorization page.

ParameterLocationRequiredTypeDescription
providerquerystringOAuth2 Provider name (e.g., "github")
redirect_uriquerystringCallback URL after authorization (optional, required by some Providers)
{
"redirect_url": "https://github.com/login/oauth/authorize?client_id=xxx&state=yyy",
"state": "a1b2c3d4e5"
}
FieldTypeDescription
redirect_urlstringFull URL to the OAuth2 Provider’s authorization page
statestringCSRF protection random state parameter; must be returned as-is in the callback

Exchange an authorization code for an access_token and refresh_token. This is the core step of the OAuth2 authorization code flow.

{
"code": "auth_code_from_callback",
"redirect_uri": "https://your-app.com/callback",
"state": "a1b2c3d4e5",
"device_id": "uuid-generated-by-client",
"device_name": "Chrome on Mac",
"user_agent": "Mozilla/5.0 ..."
}
FieldRequiredTypeDescription
codestringAuthorization code, carried in the query parameters of the authorization callback URL
redirect_uristringCallback URL, recommended to match the one from the authorization request
statestringCSRF protection state; must match the state from the authorization request and be used only once
device_idstringClient-generated device UUID, used to identify the client device
device_namestringDevice display name, e.g., "Chrome on Mac"
user_agentstringClient User-Agent, used for device identification
{
"access_token": "eyJhbGciOi...",
"refresh_token": "dGhpcyBpcyBh...",
"expires_in": 3600,
"user_id": "user-uuid"
}
FieldTypeDescription
access_tokenstringJWT access token, validity period specified by expires_in
refresh_tokenstringRefresh token, used to obtain a new token after the access_token expires
expires_inintegerAccess token expiration time (seconds), typically 3600 (1 hour)
user_idstringUnique ID of the authenticated user

💡 Refresh Token Reuse: The refresh_token can be reused multiple times within its validity period, returning a new access_token each time. The refresh_token itself is not replaced or revoked until it naturally expires (default 30 days).


Exchange a refresh_token for a new access_token. The refresh_token can be reused within its validity period.

{
"refresh_token": "dGhpcyBpcyBh..."
}
FieldRequiredTypeDescription
refresh_tokenstringRefresh token, reusable within its validity period
{
"access_token": "eyJhbGciOi...(new)",
"expires_in": 3600
}
FieldTypeDescription
access_tokenstringNew JWT access token
expires_inintegerNew access token expiration time (seconds)

All endpoints return a unified error format when an error occurs:

{
"error": "invalid_grant",
"error_description": "Authorization code has expired"
}
Error CodeHTTP StatusDescriptionCommon Causes
invalid_request400Invalid request parametersMissing required fields, format errors
invalid_client400Client authentication failedProvider misconfiguration
invalid_grant401Authorization code invalid or expiredAuthorization code already used or past its validity period
server_error500Internal server errorServer-side exception

💡 Content-Type Support: POST endpoints (/oauth2/token and /oauth2/refresh) support both application/json and application/x-www-form-urlencoded request formats.