Skip to main content

API Reference

SmarterAvatar exposes several API endpoints for integration.

Endpoints Overview

EndpointMethodPurpose
/api/chatPOSTSend message, get response
/api/get-access-tokenPOSTGet avatar session token
/api/healthGETHealth check
/api/conversations/logPOSTLog conversation data

Chat Endpoint

Send a message and receive an AI response.

Request

POST /api/chat
Content-Type: application/json

{
"message": "What products do you offer?",
"sessionId": "optional-session-id",
"history": []
}

Response

{
"response": "We offer a range of products including...",
"sources": [
{
"title": "Product Catalog",
"url": "https://example.com/catalog.pdf"
}
],
"sessionId": "generated-session-id"
}

Parameters

FieldTypeRequiredDescription
messagestringYesUser's message
sessionIdstringNoExisting session ID
historyarrayNoPrevious messages

Avatar Token Endpoint

Get a token for avatar streaming.

Request

POST /api/get-access-token
Content-Type: application/json

{
"avatarId": "Pedro_Blue_Shirt_public",
"voiceId": "voice-id"
}

Response

{
"token": "eyJ...",
"sessionId": "session-123",
"expiresAt": "2024-01-01T12:00:00Z"
}
Security

This endpoint should be called server-side. The token is short-lived and scoped to a single session.


Health Check

Verify the service is running.

Request

GET /api/health

Response

{
"status": "ok",
"timestamp": "2024-01-01T12:00:00Z",
"providers": {
"llm": "connected",
"stt": "connected",
"avatar": "connected"
}
}

Conversation Logging

Log conversation data for analytics.

Request

POST /api/conversations/log
Content-Type: application/json

{
"sessionId": "session-123",
"messages": [
{
"role": "user",
"content": "Hello"
},
{
"role": "assistant",
"content": "Hi there!"
}
],
"metadata": {
"duration": 180,
"source": "web"
}
}

Response

{
"success": true,
"conversationId": "conv-456"
}

Error Handling

All endpoints return consistent error format:

{
"error": {
"code": "INVALID_REQUEST",
"message": "Missing required field: message"
}
}

Error Codes

CodeHTTP StatusDescription
INVALID_REQUEST400Malformed request
UNAUTHORIZED401Invalid/missing auth
RATE_LIMITED429Too many requests
PROVIDER_ERROR502Upstream provider failed
INTERNAL_ERROR500Server error

Hybrid Integration

For hybrid architectures, replace the /api/chat endpoint with your backend:

Your Backend Requirements

Your API should accept:

POST /your-api/chat
Content-Type: application/json

{
"message": "User question",
"sessionId": "session-id",
"context": {}
}

And return:

{
"response": "AI response text",
"sources": []
}

Configure SmarterAvatar

Point the frontend to your backend:

NEXT_PUBLIC_CHAT_API_URL=https://your-backend.com/api/chat

The frontend will route chat requests to your backend while handling avatar/STT locally.


Rate Limits

Default rate limits (configurable):

EndpointLimit
/api/chat60/min
/api/get-access-token10/min
/api/health100/min

For higher limits, contact us.