Documentation

Unified Chat API

The Unified Chat API lets you interact with LLMs while automatically analyzing the emotional tone of both user and assistant messages.

Endpoint
POST/v1/chat/completions

Headers

x-api-key: YOUR_API_KEYContent-Type: application/json
Request Body
FieldTypeRequiredDescription
modelstringText generation model (e.g., gpt-4.1-nano)
emotion_modelstringEmotion model to apply (e.g., emotion-v1)
context_idstringSession ID for emotional memory (≤128 bytes). If omitted, response is stateless.
messagesarrayConversation history. Each object: {role: "user" | "assistant", content: string}
model_paramsobjectPass-through parameters to the text model (temperature, max_tokens, etc.)
emotion_model_paramsobjectOptions for emotion analysis (thresholds, smoothing)
streambooleanStream results in chunks (default: false)
toolsarrayTool definitions if using function/tool calling
Example Request
curl https://api.kaiko.ai/v1/chat/completions \
  -H "x-api-key: $KAIKO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4.1-nano",
    "emotion_model": "emotion-v1",
    "context_id": "chat-123",
    "messages": [
      {"role": "user", "content": "I'm nervous about my interview tomorrow."}
    ],
    "model_params": {"temperature": 0.7},
    "stream": false
  }'
Example Response
{
  "id": "chatcmpl-1757595153467",
  "object": "chat.completion",
  "created": 1757595153,
  "model": "gpt-4.1-nano",
  "emotion_model": "emotion-v1",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "It's natural to feel nervous. Want me to share some quick interview tips?"
      },
      "finish_reason": "stop"
    }
  ],
  "emotions": {
    "user": {
      "category": "fear",
      "text": "Moderate FEAR",
      "raw": {
        "fear": 0.78,
        "joy": 0.11,
        "sadness": 0.06
      }
    },
    "assistant": {
      "category": "calm",
      "text": "Calm / Supportive",
      "raw": {
        "joy": 0.42,
        "love": 0.33,
        "fear": 0.05
      }
    }
  },
  "usage": {
    "prompt_tokens": 45,
    "completion_tokens": 23,
    "analyse_tokens": 12
  }
}
Error Codes
CodeMeaningWhen it happens
401UnauthorizedMissing/invalid API key or auth header missing
404Not FoundWrong model name or expired context_id
413Payload Too LargeToo many messages / oversized input
429Rate LimitedExceeded quota; retry with backoff
500Server ErrorUnexpected error; try again or contact support if persistent
Notes
  • • Use context_id for multi-turn conversations to maintain emotional state.
  • • Without context_id, emotions are evaluated per-call (stateless).
  • • Emotions are returned for both user and assistant messages.
  • • Token usage includes prompt_tokens, completion_tokens, and analyse_tokens.

Next: see Emotion APIs for standalone emotion analysis.