All Lightfast API requests require authentication and a workspace identifier. 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 along with the X-Workspace-ID header:
Required Headers:
| Header | Description |
|---|---|
Authorization | Bearer <api-key> - Your API key |
X-Workspace-ID | The workspace ID to query |
Content-Type | application/json |
Session Authentication
For the Console UI, authentication uses Clerk session cookies. The X-Workspace-ID header is still required:
Session authentication validates that the user is a member of the organization that owns the workspace.
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)
Getting Your Workspace ID
Your workspace ID can be found in:
- The Console URL:
https://lightfast.ai/{org}/{workspace}→ workspace ID is in settings - Settings → Workspace → Workspace ID
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 |
| 400 | BAD_REQUEST | Missing X-Workspace-ID header |
| 403 | FORBIDDEN | User not authorized to access the workspace |
| 404 | NOT_FOUND | Workspace not found |
Handling Errors
Example: Complete Request
Next Steps
- POST /v1/search - Search your team's knowledge
- POST /v1/contents - Retrieve full content by ID
- POST /v1/findsimilar - Find semantically similar content
- Error Handling - Complete error code reference