HR Data Intelligence Agent API - Next.js Edition
GET /api/health - Health checkPOST /api/chat - Chat with text streamingPOST /api/chat-with-voice - Chat with text + voice synthesisPOST /api/chat-voice-stream - Chat with real-time voice streamingPOST /api/conversation/:userId/like - Like a conversationPOST /api/conversation/:userId/dislike - Dislike a conversationDELETE /api/conversation/:userId - Delete conversationGET /api/conversation/:userId - Get conversation history// Text streaming
const response = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
message: "I want to do salary fitment",
thread_id: "user-123"
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const text = decoder.decode(value);
const lines = text.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const event = JSON.parse(line.slice(6));
console.log(event);
}
}
}// With voice synthesis
const response = await fetch('/api/chat-with-voice', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
message: "Tell me about the candidates",
thread_id: "user-123",
voice: "nova",
enable_voice: true
})
});
// Events include:
// { type: "text", content: "..." }
// { type: "voice_start" }
// { type: "voice_data", format: "mp3", audio: "base64..." }
// { type: "voice_complete" }