Skip to main content
Authenticated API

This endpoint requires a valid JWT Bearer token. Accessible via the API gateway at /v1/ai/*.

NLP Services API

Natural Language Processing services for text analysis, sentiment detection, and language operations.

Overview

The NLP Services provide:

ServicePurposeUse Case
Sentiment AnalysisDetect sentiment polarityReview analysis, feedback
Topic ExtractionIdentify key topicsTrend detection
Entity RecognitionExtract named entitiesMenu items, locations
TranslationMulti-language supportLocalization
Command ParsingNatural language commandsVoice AI
Conversation AnalysisConversation insightsSupport analytics

Sentiment Analysis

Analyze Text

POST /api/v1/nlp/sentiment
Authorization: Bearer {access_token}
Content-Type: application/json

Request:

{
"text": "The food was excellent and service was fast!",
"language": "en"
}

Response:

{
"label": "positive",
"score": 0.85,
"confidence": 0.92,
"magnitude": 0.78,
"positive_terms": ["excellent", "fast"],
"negative_terms": [],
"analyzed_at": "2026-01-19T12:00:00Z"
}

Sentiment Labels

LabelScore RangeDescription
positive> 0.15Favorable sentiment
neutral-0.15 to 0.15Neutral or mixed
negative< -0.15Unfavorable sentiment

Batch Analysis

POST /api/v1/nlp/sentiment/batch
Authorization: Bearer {access_token}
Content-Type: application/json

Request:

{
"texts": [
"Great food, will come back!",
"Service was slow and cold food.",
"Average experience, nothing special."
],
"language": "en"
}

Response:

{
"results": [
{"label": "positive", "score": 0.78, "confidence": 0.88},
{"label": "negative", "score": -0.65, "confidence": 0.91},
{"label": "neutral", "score": 0.05, "confidence": 0.72}
],
"summary": {
"total": 3,
"positive": 1,
"neutral": 1,
"negative": 1,
"average_score": 0.06
}
}

Sentiment Keywords

Default positive keywords:

  • excellent, great, good, love, amazing
  • awesome, pleasant, fast, friendly, helpful
  • delicious, tasty, fresh, clean, efficient

Default negative keywords:

  • bad, poor, slow, awful, terrible
  • dirty, rude, cold, stale, overpriced
  • late, unclean, noisy, crowded, missing

Topic Extraction

Extract Topics

POST /api/v1/nlp/topics
Authorization: Bearer {access_token}
Content-Type: application/json

Request:

{
"text": "The steak was overcooked but the wine selection was impressive. Our waiter John was very knowledgeable about the menu.",
"max_topics": 5
}

Response:

{
"topics": [
{
"topic": "food_quality",
"keywords": ["steak", "overcooked"],
"sentiment": "negative",
"confidence": 0.85
},
{
"topic": "beverages",
"keywords": ["wine", "selection", "impressive"],
"sentiment": "positive",
"confidence": 0.90
},
{
"topic": "service",
"keywords": ["waiter", "knowledgeable"],
"sentiment": "positive",
"confidence": 0.82
}
],
"dominant_topic": "beverages"
}

Topic Categories

CategoryDescriptionKeywords
food_qualityFood preparation, tastecook, taste, fresh, raw
serviceStaff interactionswaiter, server, friendly
ambianceEnvironment, atmospheremusic, decor, lighting
valuePricing, value perceptionprice, expensive, worth
beveragesDrinks, barwine, cocktail, beer
wait_timeSpeed of servicewait, slow, fast, quick
cleanlinessHygiene, cleanlinessclean, dirty, sanitary

Entity Recognition

Extract Entities

POST /api/v1/nlp/entities
Authorization: Bearer {access_token}
Content-Type: application/json

Request:

{
"text": "I ordered the ribeye steak medium-rare with a side of Caesar salad and a glass of Cabernet.",
"entity_types": ["menu_item", "modifier", "beverage"]
}

Response:

{
"entities": [
{
"text": "ribeye steak",
"type": "menu_item",
"start": 13,
"end": 25,
"confidence": 0.95
},
{
"text": "medium-rare",
"type": "modifier",
"start": 26,
"end": 37,
"confidence": 0.98
},
{
"text": "Caesar salad",
"type": "menu_item",
"start": 54,
"end": 66,
"confidence": 0.92
},
{
"text": "Cabernet",
"type": "beverage",
"start": 85,
"end": 93,
"confidence": 0.89
}
]
}

Entity Types

TypeDescriptionExamples
menu_itemFood itemsburger, salad, steak
modifierCooking preferencesmedium-rare, no onions
beverageDrinkswine, beer, soda
allergenAllergen mentionspeanut, gluten, dairy
personNamesJohn, waiter
locationPlacespatio, bar, Table 7
timeTime references7pm, tonight
quantityAmountstwo, dozen, extra

Translation

Translate Text

POST /api/v1/nlp/translate
Authorization: Bearer {access_token}
Content-Type: application/json

Request:

{
"text": "Welcome to our restaurant. How may I help you today?",
"source_language": "en",
"target_language": "es"
}

Response:

{
"translated_text": "Bienvenido a nuestro restaurante. ¿Cómo puedo ayudarle hoy?",
"source_language": "en",
"target_language": "es",
"confidence": 0.96,
"alternative_translations": [
"Bienvenidos a nuestro restaurante. ¿En qué puedo ayudarles hoy?"
]
}

Supported Languages

CodeLanguageVoice Support
enEnglishYes
esSpanishYes
frFrenchYes
zhChineseYes
viVietnameseYes
koKoreanYes
jaJapaneseLimited
ptPortugueseYes
deGermanYes

Detect Language

POST /api/v1/nlp/detect-language
Authorization: Bearer {access_token}
Content-Type: application/json

Request:

{
"text": "Me gustaría ordenar una hamburguesa"
}

Response:

{
"detected_language": "es",
"confidence": 0.98,
"alternatives": [
{"language": "pt", "confidence": 0.15}
]
}

Command Parsing

Parse natural language commands for voice AI.

Parse Command

POST /api/v1/nlp/parse-command
Authorization: Bearer {access_token}
Content-Type: application/json

Request:

{
"text": "Add two cheeseburgers with no onions to table 7",
"context": {
"location_id": "loc-123",
"user_role": "server"
}
}

Response:

{
"intent": "add_item",
"confidence": 0.94,
"entities": {
"quantity": 2,
"item": "cheeseburger",
"modifiers": ["no onions"],
"table": "7"
},
"action": {
"type": "order_item",
"parameters": {
"menu_item_id": "item-cheeseburger",
"quantity": 2,
"modifiers": [{"type": "remove", "item": "onions"}],
"table_id": "table-7"
}
}
}

Supported Intents

IntentDescriptionExample
add_itemAdd item to order"Add a burger"
remove_itemRemove item"Take off the fries"
modify_itemChange item"Make that medium-rare"
check_pricePrice inquiry"How much is the steak?"
get_statusOrder status"Where's table 5's food?"
call_serverRequest assistance"We need a refill"
process_paymentPayment action"Close out table 12"

Conversation Analytics

Analyze conversation transcripts for insights.

Analyze Conversation

POST /api/v1/nlp/conversation/analyze
Authorization: Bearer {access_token}
Content-Type: application/json

Request:

{
"messages": [
{"role": "customer", "content": "Hi, I have a question about my order"},
{"role": "agent", "content": "Of course! I'd be happy to help. What's your order number?"},
{"role": "customer", "content": "It's 12345. The food was cold when it arrived."},
{"role": "agent", "content": "I apologize for that. Let me process a refund for you right away."}
],
"metrics": ["sentiment_flow", "resolution", "response_quality"]
}

Response:

{
"summary": {
"total_messages": 4,
"customer_messages": 2,
"agent_messages": 2,
"duration_estimate": "2 minutes"
},
"sentiment_flow": [
{"message": 1, "sentiment": "neutral", "score": 0.0},
{"message": 2, "sentiment": "positive", "score": 0.6},
{"message": 3, "sentiment": "negative", "score": -0.5},
{"message": 4, "sentiment": "positive", "score": 0.7}
],
"resolution": {
"issue_identified": true,
"issue_type": "food_quality",
"resolution_offered": true,
"resolution_type": "refund",
"customer_satisfied": "likely"
},
"response_quality": {
"empathy_score": 0.85,
"professionalism": 0.92,
"resolution_speed": "fast"
},
"topics_discussed": ["order_issue", "food_quality", "refund"]
}

Aggregate Sentiment

Get sentiment trends over time.

GET /api/v1/nlp/sentiment/trends?
start_date=2026-01-01&
end_date=2026-01-19&
granularity=day&
source=reviews
Authorization: Bearer {access_token}

Response:

{
"trends": [
{
"date": "2026-01-01",
"average_score": 0.65,
"positive_count": 45,
"neutral_count": 12,
"negative_count": 8,
"total": 65
},
{
"date": "2026-01-02",
"average_score": 0.58,
"positive_count": 38,
"neutral_count": 15,
"negative_count": 12,
"total": 65
}
],
"summary": {
"overall_average": 0.62,
"trend_direction": "stable",
"top_positive_topics": ["service", "food_quality"],
"top_negative_topics": ["wait_time"]
}
}

Error Responses

Invalid Language (400)

{
"error": {
"code": "INVALID_LANGUAGE",
"message": "Language 'xyz' is not supported",
"supported_languages": ["en", "es", "fr", "zh", "vi", "ko"]
}
}

Text Too Long (400)

{
"error": {
"code": "TEXT_TOO_LONG",
"message": "Text exceeds maximum length of 10000 characters",
"provided_length": 15234
}
}

Rate Limited (429)

{
"error": {
"code": "RATE_LIMITED",
"message": "NLP API rate limit exceeded",
"retry_after": 60
}
}

Best Practices

Sentiment Analysis

  1. Clean input text: Remove HTML, special characters
  2. Use batch API: For multiple texts, use batch endpoint
  3. Consider context: Review sentiment may differ from chat
  4. Monitor confidence: Low confidence may need manual review

Translation

  1. Detect first: Use language detection for unknown sources
  2. Cache results: Same text doesn't need re-translation
  3. Review critical: Human review for customer-facing content
  4. Handle failures: Graceful fallback to original language

Command Parsing

  1. Provide context: Include location, role, menu context
  2. Handle ambiguity: Confirm unclear commands
  3. Train custom: Add domain-specific vocabulary
  4. Log failures: Track unrecognized commands for improvement