All Lightfast API requests require authentication. The API supports two authentication methods: API keys for external clients and session authentication for the Console UI.
Authentication Methods
API Key Authentication
For external API clients, use an API key in the Authorization header:
Required Headers:
| Header | Description |
|---|---|
Authorization | Bearer <api-key> — Your API key (prefixed with sk-lf-) |
Content-Type | application/json |
The organization is resolved automatically from the API key's database record — no additional headers are needed.
Session Authentication
For the Console UI, authentication uses Clerk session cookies with an X-Org-ID header:
Session authentication validates that the user is a member of the specified organization.
Getting Your API Key
- Sign in to the Lightfast Console
- Navigate to Settings → API Keys
- Click Create New Key
- Copy the key immediately (it won't be shown again)
API keys are scoped to your organization. All requests made with a key are automatically associated with the organization that created it.
Security Best Practices
Use Environment Variables
Never hardcode API keys in your source code:
Environment Setup
Never Commit Keys
Add environment files to .gitignore:
Server-Side Only
API keys should only be used in server-side code:
Error Responses
Authentication errors return JSON with an error code and message:
Error Codes
| Status | Code | Description |
|---|---|---|
| 401 | UNAUTHORIZED | No authentication provided or invalid API key |
| 403 | FORBIDDEN | User not authorized to access the organization |
Handling Errors
Example: Complete Request
Next Steps
- POST /v1/search — Search your team's knowledge
- Error Handling — Complete error code reference