API Key Authentication
The RaidHub API uses API key authentication to control access and prevent abuse. API keys are passed via thex-api-key header in your requests.
Development vs Production
The API behaves differently based on where requests originate:- Development
- Production
Requests from
localhost do not require an API key.When developing locally, the API automatically allows requests without authentication. This makes it easy to get started and test the API during development.In development mode, the API sets
Access-Control-Allow-Origin: * to allow requests from any local origin.How It Works
The authentication flow is handled by the API’s verification middleware (/home/daytona/workspace/source/src/auth/api-keys.ts:95):- Development bypass: If the API is not in production mode (
!process.env.PROD), all requests are allowed with unrestricted CORS - API key validation: In production, the middleware validates the
x-api-keyheader against registered keys - Origin validation: Each API key is associated with allowed origins for CORS security
- CORS configuration: If valid, the
Access-Control-Allow-Originheader is set to your request origin
CORS and Origin Validation
API keys can be configured with origin restrictions to prevent unauthorized use:- Wildcard (
*): The key can be used from any origin - Specific origins: The key is restricted to specific domains using regex patterns
- Origin header required: For origin-restricted keys, requests must include a valid
Originheader
When you request an API key, provide the origin(s) where your application will run (e.g.,
https://yourdomain.com).Error Responses
Missing API Key
If you don’t include an API key in production:Invalid API Key
If your API key is invalid or not authorized for the request origin:401 Unauthorized status code.
Best Practices
Secure your API key
Never expose your API key in client-side code, public repositories, or version control systems. Use environment variables or secure configuration management.
Use origin restrictions
Request origin-specific API keys rather than wildcard keys to prevent unauthorized use if your key is compromised.
Server-side requests
For web applications, make API requests from your backend server rather than directly from the browser to keep your API key secure.
Getting an API Key
To request an API key for production use:- Join the RaidHub Discord
- Navigate to the developer channel
- Provide the following information:
- Your application name and description
- The origin(s) where your application will run
- Expected usage patterns
View Authentication Implementation
See the complete authentication implementation on GitHub.