Overview
The Khoj API provides comprehensive programmatic access to all of Khoj’s features including search, chat, content indexing, agents, automations, and subscriptions. The API uses RESTful conventions with JSON request and response bodies.Base URL
All API requests should be made to:API Structure
The Khoj API is organized into the following main sections:- Search - Semantic search across your indexed content
- Chat - Conversational AI interface with context awareness
- Content - Index and manage documents, files, and data sources
- Agents - Create and configure custom AI agents
- Automations - Schedule recurring tasks and queries
- Subscriptions - Manage billing and subscription status
- Authentication - Token management and OAuth flows
Authentication
Most API endpoints require authentication. See the Authentication page for details on:- Generating API tokens
- OAuth with Google
- Magic link authentication
- Including tokens in requests
Rate Limiting
API requests are rate-limited based on your subscription tier:- Free tier: Lower rate limits for most endpoints
- Premium tier: Higher rate limits and access to advanced features
Response Format
All API responses return JSON with the following structure:Success Response
Error Response
Common HTTP Status Codes
| Code | Meaning |
|---|---|
| 200 | Success |
| 201 | Created |
| 204 | No Content (successful deletion) |
| 400 | Bad Request - Invalid parameters |
| 401 | Unauthorized - Missing or invalid authentication |
| 403 | Forbidden - Valid auth but insufficient permissions |
| 404 | Not Found - Resource doesn’t exist |
| 422 | Unprocessable Entity - Validation error |
| 429 | Too Many Requests - Rate limit exceeded |
| 500 | Internal Server Error |
| 501 | Not Implemented - Feature not configured |
Common Query Parameters
Many endpoints accept these common parameters:Client identifier (e.g., “web”, “obsidian”, “emacs”)
User agent string for telemetry
SDK and Client Libraries
While Khoj doesn’t currently have official SDKs, the API is designed to be easy to integrate with standard HTTP clients in any programming language.Example with cURL
Example with Python
Example with JavaScript
Next Steps
Authentication
Set up API authentication
Search API
Search your knowledge base
Chat API
Build conversational interfaces
Content API
Index and manage content
