The Amplify API provides endpoints for project management, AI interactions, file operations, and event streaming.
REST API
The REST API handles synchronous operations:
Projects
GET /api/projects — List all projects
POST /api/projects — Create a new project
GET /api/projects/:id — Get project details
DELETE /api/projects/:id — Delete a project
Files
GET /api/projects/:id/files — List project files
GET /api/projects/:id/files/:path — Read a file
PUT /api/projects/:id/files/:path — Write a file
DELETE /api/projects/:id/files/:path — Delete a file
AI
POST /api/chat — Send a chat message
POST /api/chat/stream — Stream a chat response
Authentication
The API uses Bearer token authentication. Tokens are generated when you start the server and can be configured in amplify.config.yaml.
WebSocket API
The WebSocket API handles real-time streaming:
javascript
const ws = new WebSocket('ws://localhost:3000/api/ws');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
switch (data.type) {
case 'chat_chunk': // Streaming AI response chunk
case 'chat_complete': // Full response completed
case 'file_change': // File was modified by AI
case 'terminal': // Terminal output
case 'error': // Error occurred
}
};
WebSocket events are the primary way to receive streaming AI responses and real-time project updates.
Chat API
The chat API supports both synchronous and streaming modes:
javascript
// Synchronous (wait for complete response)
const response = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
prompt: 'Create a React component',
provider: 'openai',
model: 'gpt-4o',
projectId: 'my-project',
}),
});
// Streaming (receive chunks as they arrive)
const response = await fetch('/api/chat/stream', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
prompt: 'Create a React component',
provider: 'openai',
model: 'gpt-4o',
projectId: 'my-project',
}),
});
const reader = response.body.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
processChunk(value);
}
Events API
The events system provides real-time notifications:
javascript
// Subscribe to project events
amplify.on('project:created', (project) => { ... });
amplify.on('project:deleted', (projectId) => { ... });
// Subscribe to file events
amplify.on('file:created', (file) => { ... });
amplify.on('file:modified', (file) => { ... });
amplify.on('file:deleted', (filePath) => { ... });
// Subscribe to AI events
amplify.on('chat:started', (conversation) => { ... });
amplify.on('chat:completed', (response) => { ... });
amplify.on('chat:error', (error) => { ... });
Events are delivered via WebSocket and can be used to build custom UI reactions.
Configure API settings