6.1 KiB
API Reference
Complete REST API for Open Notebook. All endpoints are served from the API backend (default: http://localhost:5055).
Base URL: http://localhost:5055 (development) or environment-specific production URL
Interactive Docs: Use FastAPI's built-in Swagger UI at http://localhost:5055/docs for live testing and exploration. This is the primary reference for all endpoints, request/response schemas, and real-time testing.
Quick Start
1. Authentication
Simple password-based (development only):
curl http://localhost:5055/api/notebooks \
-H "Authorization: Bearer your_password"
⚠️ Production: Replace with OAuth/JWT. See Security Configuration for details.
2. Base API Flow
Most operations follow this pattern:
- Create a Notebook (container for research)
- Add Sources (PDFs, URLs, text)
- Query via Chat or Search
- View results and Notes
3. Testing Endpoints
Instead of memorizing endpoints, use the interactive API docs:
- Navigate to
http://localhost:5055/docs - Try requests directly in the browser
- See request/response schemas in real-time
- Test with your own data
API Endpoints Overview
Main Resource Types
Notebooks - Research projects containing sources and notes
GET/POST /notebooks- List and createGET/PUT/DELETE /notebooks/{id}- Read, update, delete
Sources - Content items (PDFs, URLs, text)
GET/POST /sources- List and add contentGET /sources/{id}- Fetch source detailsPOST /sources/{id}/retry- Retry failed processingGET /sources/{id}/download- Download original file
Notes - User-created or AI-generated research notes
GET/POST /notes- List and createGET/PUT/DELETE /notes/{id}- Read, update, delete
Chat - Conversational AI interface
GET/POST /chat/sessions- Manage chat sessionsPOST /chat/execute- Send message and get responsePOST /chat/context/build- Prepare context for chat
Search - Find content by text or semantic similarity
POST /search- Full-text or vector searchPOST /ask- Ask a question (search + synthesize)
Transformations - Custom prompts for extracting insights
GET/POST /transformations- Create custom extraction rulesPOST /sources/{id}/insights- Apply transformation to source
Models - Configure AI providers
GET /models- Available modelsGET /models/defaults- Current defaultsPOST /models/config- Set defaults
Health & Status
GET /health- Health checkGET /commands/{id}- Track async operations
Authentication
Current (Development)
All requests require password header:
curl -H "Authorization: Bearer your_password" http://localhost:5055/api/notebooks
Password configured via OPEN_NOTEBOOK_PASSWORD environment variable.
📖 See Security Configuration for complete authentication setup, API examples, and production hardening.
Production
⚠️ Not secure. Replace with:
- OAuth 2.0 (recommended)
- JWT tokens
- API keys
See Security Configuration for production setup.
Common Patterns
Pagination
# List sources with limit/offset
curl 'http://localhost:5055/sources?limit=20&offset=10'
Filtering & Sorting
# Filter by notebook, sort by date
curl 'http://localhost:5055/sources?notebook_id=notebook:abc&sort_by=created&sort_order=asc'
Async Operations
Some operations (source processing, podcast generation) return immediately with a command ID:
# Submit async operation
curl -X POST http://localhost:5055/sources -F async_processing=true
# Response: {"id": "source:src001", "command_id": "command:cmd123"}
# Poll status
curl http://localhost:5055/commands/command:cmd123
Streaming Responses
The /ask endpoint streams responses as Server-Sent Events:
curl -N 'http://localhost:5055/ask' \
-H "Content-Type: application/json" \
-d '{"question": "What is AI?"}'
# Outputs: data: {"type":"strategy",...}
# data: {"type":"answer",...}
# data: {"type":"final_answer",...}
Multipart File Upload
curl -X POST http://localhost:5055/sources \
-F "type=upload" \
-F "notebook_id=notebook:abc" \
-F "file=@document.pdf"
Error Handling
All errors return JSON with status code:
{"detail": "Notebook not found"}
Common Status Codes
| Code | Meaning | Example |
|---|---|---|
| 200 | Success | Operation completed |
| 400 | Bad Request | Invalid input |
| 404 | Not Found | Resource doesn't exist |
| 409 | Conflict | Resource already exists |
| 500 | Server Error | Database/processing error |
Tips for Developers
- Start with interactive docs (
http://localhost:5055/docs) - this is the definitive reference - Enable logging for debugging (check API logs:
docker logs) - Streaming endpoints require special handling (Server-Sent Events, not standard JSON)
- Async operations return immediately; always poll status before assuming completion
- Vector search requires embedding model configured (check
/models) - Model overrides are per-request; set in body, not config
- CORS enabled in development; configure for production
Learning Path
- Authentication: Add
X-Passwordheader to all requests - Create a notebook:
POST /notebookswith name and description - Add a source:
POST /sourceswith file, URL, or text - Query your content:
POST /chat/executeto ask questions - Explore advanced features: Search, transformations, streaming
Production Considerations
- Replace password auth with OAuth/JWT (see Security)
- Add rate limiting via reverse proxy (Nginx, CloudFlare, Kong)
- Enable CORS restrictions (currently allows all origins)
- Use HTTPS via reverse proxy (see Reverse Proxy)
- Set up API versioning strategy (currently implicit)
See Security Configuration and Reverse Proxy Setup for complete production setup.