Authentication & Security
Weir AI API v1.0.1 provides multiple authentication methods designed for different use cases and security requirements. This guide covers all authentication mechanisms, security best practices, and token management strategies.Authentication Methods
The Weir AI API supports different authentication methods depending on the API category you’re using:Basic Authentication
Used for External APIs to generate access tokens with client credentials.
Bearer Token
Used for authenticated requests with access tokens across all API categories.
Session-based
Used for Console and Admin APIs with username/password authentication.
External API Authentication
External APIs use basic authentication to generate access tokens for third-party integrations.Generate Access Token
Basic authentication header with base64-encoded client credentials. Format:
Basic base64(client_id:secret_key)JWT access token for authenticated API requests. Valid for 1 hour.
Token expiration time in seconds (3600 = 1 hour).
Token type, always “Bearer” for this API.
Console API Authentication
Console APIs use session-based authentication with username/password login and token refresh capabilities.Registration
User’s full name for the account.
Valid email address for the account. Must be unique.
Secure password for the account. Minimum 8 characters with mixed case, numbers, and symbols.
Organization details for the new account.
Mobile Registration
OTP Validation
OTP session ID received from registration response.
6-digit OTP code sent to the registered email address.
Resend OTP
OTP session ID to resend the OTP for.
Login
User’s full name or email address.
User’s password.
JWT access token for authenticated API requests. Valid for 1 hour.
Refresh token for obtaining new access tokens. Valid for 30 days.
User information including ID, name, email, and role.
Refresh Token
Valid refresh token obtained from login.
Logout
Refresh token to invalidate during logout.
Admin API Authentication
Admin APIs use a special authentication method for administrative access.Admin Authentication
Special admin authentication token provided by system administrators.
Using Access Tokens
Once you have an access token, include it in the Authorization header for all authenticated requests:Security Best Practices
Token Management
Secure Storage
Secure Storage
- Store access tokens securely in environment variables or secure key management systems
- Never hardcode tokens in your source code
- Use different tokens for different environments (development, staging, production)
- Implement token rotation for long-lived applications
Token Refresh
Token Refresh
- Implement automatic token refresh before expiration
- Handle refresh token expiration gracefully
- Use exponential backoff for failed refresh attempts
- Store refresh tokens securely alongside access tokens
Error Handling
Error Handling
- Handle 401 Unauthorized responses by refreshing tokens
- Implement proper error logging without exposing sensitive information
- Use retry mechanisms for transient authentication failures
- Provide clear error messages to users when authentication fails
Request Security
HTTPS Only
HTTPS Only
- Always use HTTPS for all API requests
- Never send authentication credentials over unencrypted connections
- Validate SSL certificates in production environments
- Use certificate pinning for mobile applications
Header Security
Header Security
- Always include the
x-sourceheader for Console and Admin APIs - Use appropriate Content-Type headers
- Avoid exposing sensitive information in request headers
- Implement proper CORS policies for web applications
Input Validation
Input Validation
- Validate all input parameters before sending requests
- Sanitize user input to prevent injection attacks
- Use strong password requirements for user registration
- Implement rate limiting on authentication endpoints
Rate Limiting
The Weir AI API implements rate limiting to ensure fair usage and system stability:Authentication Endpoints
- Login: 5 requests per minute per IP
- Registration: 3 requests per minute per IP
- Token Refresh: 10 requests per minute per user
API Endpoints
- External APIs: 100 requests per minute per client
- Console APIs: 200 requests per minute per user
- Admin APIs: 500 requests per minute per admin
Rate Limit Headers
All API responses include rate limiting information:Maximum number of requests allowed per time window.
Number of requests remaining in the current time window.
Unix timestamp when the rate limit window resets.
Handling Rate Limits
Monitor Rate Limit Headers
Check the rate limit headers in API responses to monitor your usage.
Implement Exponential Backoff
When you hit rate limits, implement exponential backoff with jitter.
Cache Responses
Cache API responses when possible to reduce the number of requests.
Error Handling
Common Authentication Errors
401 Unauthorized
401 Unauthorized
403 Forbidden
403 Forbidden
- Check your user role and permissions
- Contact your organization administrator for access
- Verify you’re using the correct API category for your use case
429 Too Many Requests
429 Too Many Requests
- Implement exponential backoff
- Reduce request frequency
- Cache responses when possible
Token Lifecycle Management
Token Generation
Generate access tokens through appropriate authentication endpoints based on your API category.
Token Usage
Use access tokens in the Authorization header for all authenticated requests.
Token Refresh
Refresh access tokens before they expire using the refresh token endpoint.
Token Invalidation
Invalidate tokens through logout or when they’re compromised.