Exchange Service Token
Exchange service API key for short-lived JWT.
This endpoint allows registered service accounts to exchange their API key for a short-lived JWT token (5 minutes TTL). The JWT can then be used to authenticate with other services.
Requirements: - Valid API key in X-API-Key header - API key must have is_service_account=true
The returned JWT contains: - sub: “service:{service_name}” - service_name: Service identity - business_id: Optional business context (null for multi-tenant) - scope: “multi-tenant” or “single-tenant” (FR-TOKEN-001) - permissions: Service-specific permissions - token_type: “service”
Multi-tenant tokens (business_id=null) require allow_multi_tenant=True on the API key per FR-SERVICE-003 and FR-SERVICE-004.
Args: request: Service token request with service_name and optional business_id x_api_key: Service API key from X-API-Key header db: Database session from dependency injection
Returns: ServiceTokenResponse with access_token and expires_in
Raises: 401: If API key is invalid or revoked 403: If API key is not a service account or lacks multi-tenant permission
Parameters
Section titled “ Parameters ”Header Parameters
Section titled “Header Parameters ”Request Body required
Section titled “Request Body required ”Request body for service token exchange.
Attributes: service_name: Identity of the requesting service business_id: Optional business context for scoped operations
Responses
Section titled “ Responses ”Successful Response
Response from service token exchange.
Attributes: access_token: JWT access token for service authentication token_type: Token type (always ‘Bearer’) expires_in: Token TTL in seconds
object
JWT access token
Token type
Token TTL in seconds
Invalid API key
Example
{ "detail": { "error": "invalid_api_key" }}API key is not a service account or multi-tenant not allowed
Examples
{ "detail": { "error": "not_service_account" }}{ "detail": { "error": "multi_tenant_not_allowed", "message": "API key does not have multi-tenant permission" }}Validation Error
object
object
object
Rate limited
Example
{ "detail": { "error": "rate_limited", "retry_after": 60 }}