Practical implementation guides for common V2 use cases. Each guide demonstrates how to leverage the new EQ dimensions, trajectory tracking, and conversation mode detection.
Build a chatbot that adapts its tone based on user emotions, using intensity levels and conversation modes.
Analyze social media posts at scale using batch processing with V2 valence and arousal dimensions.
Track emotional progress over sessions for coaching apps with breakthrough and growth detection.
Detect hostility and escalation risks using V2 hostility detection and emotion intensity.
Use the Unified Chat API with V2 emotion model to create a chatbot that understands user emotions and adapts its responses accordingly.
// Empathetic Chatbot with V2 EQ Dimensions
async function handleUserMessage(userId, message) {
const contextId = `user-${userId}-session`;
const response = await fetch('https://api.kaikostudios.xyz/v2/chat/completions', {
method: 'POST',
headers: {
'x-api-key': process.env.KAIKO_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-4',
emotion_model: 'emotion-v2',
context_id: contextId,
messages: [
{ role: 'system', content: buildSystemPrompt() },
{ role: 'user', content: message }
],
model_params: { temperature: 0.7, max_tokens: 500 }
})
});
const data = await response.json();
const userEmotion = data.emotions.user;
const mode = data.conversationMode;
// Adapt response based on V2 EQ dimensions
if (userEmotion.intensityLevel === 'critical' ||
userEmotion.intensityLevel === 'high') {
// High intensity - prioritize acknowledgment
console.log('High emotional intensity detected');
}
if (mode?.mode === 'crisis_intervention') {
// Trigger safety protocols
await escalateToHumanSupport(userId);
}
// Use valence for quick sentiment
const sentiment = userEmotion.valence > 0.3 ? 'positive' :
userEmotion.valence < -0.3 ? 'negative' : 'neutral';
return {
reply: data.choices[0].message.content,
emotion: userEmotion.category,
intensity: userEmotion.intensity,
valence: userEmotion.valence,
mode: mode?.mode,
sentiment
};
}
function buildSystemPrompt() {
return `You are an empathetic AI assistant. When users express:
- High fear/anxiety: Provide reassurance and grounding
- Sadness: Validate feelings, offer support
- Anger: Acknowledge frustration, stay calm
- Joy: Celebrate with them, encourage positivity
- Complex emotions: Explore with curiosity and patience`;
}Use the V2 Batch Analysis API to process social media posts at scale and extract sentiment metrics.
// Social Media Sentiment Analysis with V2 Batch API
async function analyzeSentiment(posts) {
const response = await fetch('https://api.kaikostudios.xyz/v2/emotions/batch-analysis', {
method: 'POST',
headers: {
'x-api-key': process.env.KAIKO_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'emotion-v2',
messages: posts.map(post => ({
content: { text: post.text }
}))
})
});
const data = await response.json();
// Process V2 emotions with EQ dimensions
return data.emotions.map((emotion, index) => ({
postId: posts[index].id,
category: emotion.category,
intensity: emotion.intensity,
valence: emotion.valence,
arousal: emotion.arousal,
sentiment: emotion.valence > 0.3 ? 'positive' :
emotion.valence < -0.3 ? 'negative' : 'neutral',
urgency: emotion.arousal > 0.7 && emotion.valence < -0.3 ? 'high' : 'normal'
}));
}
async function monitorBrandMentions() {
const posts = await fetchRecentMentions(); // Your data source
const analyzed = await analyzeSentiment(posts);
// Filter for urgent negative sentiment
const urgent = analyzed.filter(a => a.urgency === 'high');
if (urgent.length > 0) {
await notifyTeam(urgent);
}
// Aggregate sentiment metrics
const avgValence = analyzed.reduce((sum, a) => sum + a.valence, 0) / analyzed.length;
const distribution = {
positive: analyzed.filter(a => a.sentiment === 'positive').length,
neutral: analyzed.filter(a => a.sentiment === 'neutral').length,
negative: analyzed.filter(a => a.sentiment === 'negative').length
};
return { avgValence, distribution, analyzed };
}Track emotional progress over multiple sessions using V2's context-based analysis with trajectory and growth insights.
// Emotional Trajectory Tracking for Coaching Apps
async function trackSession(userId, message) {
const contextId = `coaching-${userId}`;
const response = await fetch(
`https://api.kaikostudios.xyz/v2/emotions/${contextId}/analysis`,
{
method: 'POST',
headers: {
'x-api-key': process.env.KAIKO_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'emotion-v2',
messages: [{
role: 'user',
externalId: `msg-${Date.now()}`,
content: { text: message },
timestamp: new Date().toISOString()
}]
})
}
);
const data = await response.json();
// Check for breakthrough moments
if (data.trajectory?.breakthrough?.detected) {
await recordBreakthrough(userId, {
type: data.trajectory.breakthrough.type,
significance: data.trajectory.breakthrough.significance
});
}
// Track growth over time
if (data.growth) {
await updateGrowthMetrics(userId, data.growth);
}
// Monitor emotional volatility
const volatility = data.trajectory?.baseline?.emotionalVolatility;
if (volatility > 0.6) {
console.log('High emotional volatility detected');
}
return {
current: data.emotions.user,
trend: data.trajectory?.trend?.direction,
breakthrough: data.trajectory?.breakthrough?.detected,
discoveryLevel: data.emotions.user.discoveryLevel
};
}Use V2's hostility detection and emotion analysis to flag concerning content before it causes harm.
// Content Moderation with Hostility Detection
async function moderateContent(content) {
const response = await fetch('https://api.kaikostudios.xyz/v2/emotions/analysis', {
method: 'POST',
headers: {
'x-api-key': process.env.KAIKO_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'emotion-v2',
messages: [{ content: { text: content } }]
})
});
const data = await response.json();
const emotion = data.emotions._default;
// Check for concerning patterns
const flags = [];
if (emotion.hostilityState?.level === 'high') {
flags.push({
type: 'hostility',
severity: 'high',
recommendation: emotion.hostilityState.recommendedResponse
});
}
// High anger + high arousal = potential escalation
if (emotion.raw?.anger > 0.7 && emotion.arousal > 0.8) {
flags.push({
type: 'escalation_risk',
severity: 'medium'
});
}
// Check for distress signals
if (emotion.category === 'fear' && emotion.intensity > 0.8) {
flags.push({
type: 'distress',
severity: 'high'
});
}
return {
approved: flags.length === 0,
flags,
emotion: emotion.category,
intensity: emotion.intensity,
valence: emotion.valence
};
}Next: See Unified Chat API for full API reference, or V2 EQ Dimensions for detailed dimension explanations.