KrosAI Docs
DashboardGet Started
  • Getting Started
    • Introduction
    • Quickstart Guide
    • Authentication
  • OpenAI SDK Compatability
  • Endpoints
    • Completions API
      • Create Chat Completion
    • Translation API
    • Text Summarization API
    • Audio Transcription API
    • Sentiment Analysis API
  • AGENT
    • Agents API
      • Create Agent
      • List Agents
      • Get Agent
      • Update Agent
      • Delete Agent
      • Start Voice Session
    • Conversations API
      • Create Conversation
      • List Conversations
      • Get Conversation
      • Get Conversation Messages
    • Knowledge Base API
      • Create Knowledge Base
      • List Knowledge Base
      • Upload Document
      • List Document
  • Resources
    • AI Voice Agents
    • In-App Voice Assistants
    • Virtual Health Assistants
    • EdTech Language Tutors
  • SDKS
    • Node.JS SDK
    • React Native SDK
    • Flutter
Powered by GitBook
On this page
  • Example Request
  • Response Format
  • Batch Processing
  • Best Practices
  • Error Handling
  1. Endpoints

Sentiment Analysis API

Analyze sentiment in multiple languages using KrosAI’s models

PreviousAudio Transcription APINextAgents API

Last updated 1 month ago

The KrosAI Sentiment Analysis API analyzes text to determine sentiment and emotional tone, with robust support for African languages. This is particularly useful for understanding customer feedback, social media monitoring, and market research in low-resource languages.

Overview

The sentiment analysis API examines text content and returns a sentiment classification (positive, negative, neutral, or mixed) along with confidence scores and optional detailed analysis.

Endpoint

POST https://api.krosai.com/v1/sentiment

Request Parameters

Parameter
Type
Required
Description

text

string

Yes

The text to analyze (1-5000 characters)

language

string

No

Optional language specification (e.g., "yoruba", "english", "swahili")

model

string

No

Model to use (default: "KrosMlingual2.0.1")

detailed

boolean

No

Whether to include detailed sentiment scores and emotion analysis (default: false)

Example Request

{
  "text": "I am very happy with the service provided. Thank you!",
  "language": "english",
  "detailed": true
}

Response Format

{
  "id": "sent_1234567890",
  "object": "sentiment_analysis",
  "created": 1682456789,
  "model": "KrosMlingual2.0.1",
  "results": {
    "sentiment": "positive",
    "confidence": 0.92,
    "details": {
      "positive_score": 0.92,
      "neutral_score": 0.06,
      "negative_score": 0.02,
      "emotions": {
        "joy": 0.85,
        "satisfaction": 0.78,
        "contentment": 0.65
      }
    }
  },
  "language": {
    "detected": "english",
    "confidence": 0.99
  },
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 45,
    "total_tokens": 70
  }
}

Batch Processing

For analyzing multiple texts in a single request, use the batch endpoint:

POST https://api.krosai.com/v1/sentiment/batch

Batch Request Example

{
  "texts": [
    {
      "text": "The product works perfectly!",
      "language": "english"
    },
    {
      "text": "أنا لا أحب هذه الخدمة على الإطلاق.",
      "language": "arabic"
    }
  ],
  "detailed": true
}

This returns an array of sentiment analysis results for each text.

Supported Languages

The API specializes in African languages, including:

  • Yoruba

  • English

  • Hausa

  • Igbo

  • Swahili

  • Pidgin

  • Arabic

  • French

  • Spanish

  • Portuguese

  • Amharic

  • Zulu

  • Xhosa

  • Somali

  • Oromo

Best Practices

Sentiment Analysis

  • Provide longer text samples for more accurate sentiment analysis

  • When language is known, specify it for better accuracy

  • Use detailed analysis for deeper insights into sentiment

Error Handling

All APIs return standard HTTP status codes:

  • 200: Success

  • 400: Bad request (check parameters)

  • 401: Unauthorized (check API key)

  • 429: Rate limit exceeded

  • 500: Server error

Error responses include a detail field with more information about the error.

This endpoint is OpenAI compatible