Noteon provides a minimal API surface for AI-powered features. All APIs are internal and designed to work with the frontend application.
http://localhost:3000/api
Currently, no authentication is required as all data is local. API keys for AI providers are configured via environment variables.
Stream chat responses with context from your notes.
Headers:
Content-Type: application/json
Request Body:
{
"messages": [
{
"role": "user",
"content": "What did I write about project planning?"
}
]
}Response:
- Streaming response using Server-Sent Events (SSE)
- Content-Type:
text/event-stream
Example:
const response = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ messages })
});
const reader = response.body.getReader();
// Handle streaming responseStatus Codes:
200: Success400: Bad request (invalid message format)500: Server error
Execute AI-powered commands on note content.
Headers:
Content-Type: application/json
Request Body:
{
"prompt": "Summarize this note: [note content]"
}Response:
{
"result": "Summary of the note content..."
}Supported Commands:
- Summarize
- Expand
- Rewrite
- Fix grammar
- Translate
- Custom prompts
Example:
const response = await fetch('/api/ai-command', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
prompt: 'Fix grammar: ' + noteContent
})
});
const data = await response.json();
console.log(data.result);Status Codes:
200: Success400: Bad request (missing prompt)500: Server error
Currently, no rate limiting is implemented. For production deployments, consider:
- Implementing rate limiting middleware
- Using API keys for external access
- Setting up request quotas
All API endpoints return errors in the following format:
{
"error": "Error message description",
"code": "ERROR_CODE"
}Common Error Codes:
INVALID_REQUEST: Malformed request bodyAI_PROVIDER_ERROR: Error from AI providerINTERNAL_ERROR: Server-side error
# Required for AI features
GOOGLE_GENERATIVE_AI_API_KEY=your_api_key_here
# Optional: Configure AI model
AI_MODEL=gemini-pro- Maximum duration: 30 seconds (configured in route handlers)
- Streaming timeout: 60 seconds
import { useChat } from '@ai-sdk/react';
function ChatComponent() {
const { messages, input, handleInputChange, handleSubmit } = useChat({
api: '/api/chat',
});
return (
<form onSubmit={handleSubmit}>
<input value={input} onChange={handleInputChange} />
<button type="submit">Send</button>
</form>
);
}async function executeCommand(prompt: string) {
try {
const response = await fetch('/api/ai-command', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt }),
});
if (!response.ok) {
throw new Error('API request failed');
}
const data = await response.json();
return data.result;
} catch (error) {
console.error('Command execution failed:', error);
throw error;
}
}- Error Handling: Always wrap API calls in try-catch blocks
- Loading States: Show loading indicators during streaming
- Retry Logic: Implement exponential backoff for failed requests
- Caching: Cache responses when appropriate
- Abort Controllers: Use AbortController for cancellable requests
- Maximum request size: 10MB
- Maximum response time: 30 seconds
- Streaming responses only for chat endpoint
- No batch operations currently supported
Planned endpoints for future releases:
/api/export- Export notes in various formats/api/import- Import notes from other apps/api/sync- Cloud sync functionality/api/share- Share notes with others