API Authentication
All CRAFT API endpoints require authentication via JWT tokens issued by Keycloak. This page covers how to obtain tokens, authenticate requests, and handle token refresh.Authentication Methods
- User Tokens (OIDC)
- Client Credentials
- Development Tokens
For interactive applications, use the OIDC Authorization Code flow with PKCE:After the user authenticates, exchange the code:
- Redirect the user to the Keycloak authorization endpoint
- Exchange the authorization code for tokens
- Include the access token in API requests
Using the Token
Include the access token in theAuthorization header of every API request:
Required Headers
The
X-Project-ID header determines which project the request is scoped to. A single JWT token can access multiple projects within the same organization. The project ID is never embedded in the JWT.Token Refresh
Access tokens have a short lifetime (typically 5 minutes). Use the refresh token to obtain new access tokens without re-authentication:Refresh Strategy
1
Monitor token expiry
Track the
exp claim in the JWT payload. Plan to refresh when 75% of the token lifetime has elapsed.2
Proactive refresh
Refresh the token before it expires to avoid 401 errors during in-flight requests.
3
Handle refresh failure
If the refresh token is expired or revoked, redirect the user to the login flow. For service accounts, obtain a new token via client credentials.
SDK Authentication
The auto-generated SDKs follow the openapi-python-client andopenapi-generator patterns — an AuthenticatedClient with a token constructor
arg + per-endpoint module functions, not an object/fluent client. See the
Python SDK and TypeScript SDK overviews
for the full client model.
- Python
- TypeScript
Token Claims
The JWT access token contains these claims used by the platform:Error Responses
Authentication failures return structured error responses:Next Steps
API Overview
Review the full API structure, endpoints, and rate limits.
Error Codes
Understand all error response formats and troubleshooting steps.
SSO Integration
Configure SSO for enterprise identity providers.
RBAC Configuration
Set up roles and permissions for API access control.

