Overview
OpenFang supports optional Bearer token authentication for securing API access. When enabled, all requests must include a valid API key.Configuration
Set the API key in~/.openfang/config.toml:
Authentication Methods
OpenFang accepts API keys via two methods:1. Authorization Header (Recommended)
Include the API key as a Bearer token:2. X-API-Key Header (Alternative)
For clients that can’t set Authorization headers:Security Features
Constant-Time Comparison
API key validation uses constant-time comparison viasubtle::ConstantTimeEq to prevent timing attacks:
Loopback Exemption
Requests from127.0.0.1 or ::1 bypass authentication when API key is set, allowing local CLI access:
This means you can use
openfang CLI commands locally without needing to pass the API key, even when authentication is enabled.Error Responses
When authentication fails, the API returns: Status Code:401 Unauthorized
Headers:
WebSocket Authentication
WebSocket connections (/api/agents/{id}/ws) also support Bearer authentication:
Rate Limiting
Authenticated requests are subject to the same rate limits as unauthenticated requests:- 30 requests/second per IP (default)
- Configurable via GCRA rate limiter
Best Practices
Use Strong Keys
Generate API keys with at least 32 bytes of entropy:
Rotate Regularly
Change API keys periodically and after any suspected compromise
HTTPS in Production
Always use HTTPS when exposing the API over a network
Environment Variables
Store API keys in environment variables, not in code:
Signed Manifests
For enhanced security when spawning agents, OpenFang supports Ed25519-signed manifests:403 Forbidden.
Audit Trail
All authentication events are logged to the audit trail:Next Steps
Agents API
Start making authenticated requests to spawn and manage agents