Skip to main content

XAI

The XAI API provides a comprehensive suite of AI-powered endpoints for content generation, analysis, and processing. Transform your applications with intelligent text generation, sentiment analysis, classification, extraction, translation, and vectorization capabilities.

Operations Overview

OperationDescription
xai.generateGenerate new content based on user prompts
xai.summarizeCreate concise summaries of long-form content
xai.classifyCategorize content into predefined or custom classifications
xai.sentimentAnalyze emotional tone and sentiment of text
xai.extractExtract specific entities and information from content
xai.translateTranslate content between languages
xai.vectorizeConvert text content into vector embeddings

1. Generate Content

POST xai.generate

Generate new content based on user prompts with customizable style, length, and specific instructions.

Request Body

{
"op": "xai.generate",
"user_input": "Write a blog post about the benefits of cloud computing for small businesses",
"options": {
"content_length": 800,
"content_style": "professional",
"custom_instructions": "Include practical examples and focus on cost savings. Use a conversational tone that appeals to business owners who may not be tech-savvy."
}
}

Parameters

  • op (string, required): Must be "xai.generate"
  • user_input (string, required): The prompt or instruction for content generation
  • options (object, optional): Generation configuration
    • content_length (integer): Target word count for the output
    • content_style (string): Writing style (e.g., "formal", "casual", "persuasive", "technical")
    • custom_instructions (string): Specific requirements and guidelines

Response

{
"data": {
"output": "# Cloud Computing: A Game-Changer for Small Businesses\n\nIn today's competitive landscape, small businesses need every advantage they can get. Cloud computing has emerged as a powerful tool that levels the playing field, offering enterprise-grade capabilities without the enterprise-grade costs...\n\n## Cost Savings That Matter\n\nConsider Sarah's bakery: by moving to cloud-based point-of-sale and inventory systems, she eliminated the need for expensive on-site servers and reduced her IT costs by 60%. The monthly subscription model meant predictable expenses instead of surprise hardware failures..."
},
"meta": {
"content_length": 847,
"generation_time_ms": 2340,
"style_applied": "professional"
}
}

Use Cases

Marketing Content:

{
"op": "xai.generate",
"user_input": "Create social media posts for a new fitness app launch",
"options": {
"content_style": "engaging",
"custom_instructions": "Create 5 different posts for Instagram, Twitter, and LinkedIn. Include relevant hashtags and call-to-action phrases."
}
}

Technical Documentation:

{
"op": "xai.generate",
"user_input": "Explain how to implement OAuth 2.0 authentication",
"options": {
"content_length": 1200,
"content_style": "technical",
"custom_instructions": "Include code examples in JavaScript and Python. Structure as a step-by-step tutorial."
}
}

Creative Writing:

{
"op": "xai.generate",
"user_input": "Write a short story about a robot learning to understand human emotions",
"options": {
"content_length": 1500,
"content_style": "narrative",
"custom_instructions": "Use third-person perspective. Include dialogue and focus on character development."
}
}

2. Summarize Content

POST xai.summarize

Create concise, informative summaries of long-form content while preserving key information and context.

Request Body

{
"op": "xai.summarize",
"content": "Artificial intelligence has been transforming industries across the globe at an unprecedented pace. From healthcare to finance, manufacturing to retail, AI technologies are revolutionizing how businesses operate and deliver value to customers. Machine learning algorithms can now process vast amounts of data in real-time, identifying patterns and insights that would be impossible for humans to detect manually. This capability has led to breakthrough innovations in personalized medicine, where AI systems can analyze genetic data to recommend tailored treatment plans for individual patients. In the financial sector, AI-powered fraud detection systems can identify suspicious transactions within milliseconds, protecting both consumers and institutions from financial crimes...",
"options": {
"content_length": 150,
"content_style": "executive",
"custom_instructions": "Focus on business impact and include specific industry examples. Write for C-level executives."
}
}

Parameters

  • op (string, required): Must be "xai.summarize"
  • content (string, required): The text content to summarize
  • options (object, optional): Summarization configuration
    • content_length (integer): Target length for the summary
    • content_style (string): Summary style (e.g., "executive", "bullet-points", "academic")
    • custom_instructions (string): Specific focus areas or requirements

Response

{
"data": {
"output": "AI is revolutionizing industries globally through real-time data processing and pattern recognition. Key applications include personalized medicine with genetic analysis for tailored treatments, and financial fraud detection systems that identify threats within milliseconds. These technologies enable businesses to deliver enhanced customer value while protecting against risks, demonstrating AI's transformative impact across healthcare, finance, and other sectors."
},
"meta": {
"original_length": 2847,
"summary_length": 147,
"compression_ratio": 0.052,
"processing_time_ms": 1820
}
}

Use Cases

Document Processing:

{
"op": "xai.summarize",
"content": "[Long research paper content...]",
"options": {
"content_length": 300,
"content_style": "academic",
"custom_instructions": "Extract key findings, methodology, and conclusions. Include statistical significance where mentioned."
}
}

Meeting Notes:

{
"op": "xai.summarize",
"content": "[Transcript of 2-hour meeting...]",
"options": {
"content_style": "bullet-points",
"custom_instructions": "Focus on action items, decisions made, and next steps. Organize by department or project."
}
}

News Briefing:

{
"op": "xai.summarize",
"content": "[Multiple news articles...]",
"options": {
"content_length": 200,
"content_style": "news-brief",
"custom_instructions": "Highlight the most important developments and their potential impact. Maintain neutral tone."
}
}

3. Classify Content

POST xai.classify

Categorize content into predefined classifications or custom categories with confidence scoring.

Request Body

{
"op": "xai.classify",
"content": "I'm really disappointed with my recent purchase. The product arrived damaged and the customer service team was unhelpful when I tried to return it. The whole experience has been frustrating and I'm considering switching to a competitor.",
"options": {
"confidence_level": "high",
"classification_categories": "positive, negative, neutral, urgent, spam, complaint, inquiry, compliment"
}
}

Parameters

  • op (string, required): Must be "xai.classify"
  • content (string, required): The text content to classify
  • options (object, optional): Classification configuration
    • confidence_level (string): Minimum confidence threshold ("low", "medium", "high")
    • classification_categories (string): Comma-separated list of possible categories

Response

{
"data": {
"output": {
"primary_classification": "complaint",
"secondary_classifications": ["negative", "urgent"],
"confidence_scores": {
"complaint": 0.92,
"negative": 0.89,
"urgent": 0.76,
"neutral": 0.08,
"positive": 0.03
},
"reasoning": "Content expresses clear dissatisfaction with product quality and service experience, indicating a customer complaint requiring urgent attention."
}
},
"meta": {
"classification_method": "multi-label",
"confidence_threshold": 0.7,
"processing_time_ms": 890
}
}

Use Cases

Customer Support Tickets:

{
"op": "xai.classify",
"content": "[Customer email content...]",
"options": {
"classification_categories": "billing, technical, general inquiry, feature request, bug report, cancellation"
}
}

Content Moderation:

{
"op": "xai.classify",
"content": "[User-generated content...]",
"options": {
"classification_categories": "appropriate, inappropriate, spam, harassment, hate speech, off-topic",
"confidence_level": "high"
}
}

Document Organization:

{
"op": "xai.classify",
"content": "[Business document content...]",
"options": {
"classification_categories": "contract, invoice, report, proposal, legal, hr, marketing, technical"
}
}

4. Sentiment Analysis

POST xai.sentiment

Analyze the emotional tone, sentiment, and subjective aspects of text content with detailed insights.

Request Body

{
"op": "xai.sentiment",
"content": "The new product launch exceeded all our expectations! The team worked incredibly hard, and while there were some initial challenges with the supply chain, we managed to overcome them. Customer feedback has been overwhelmingly positive, though a few users mentioned minor usability issues that we're already addressing.",
"options": {
"analysis_depth": "detailed",
"specific_aspects": "product quality, team performance, customer satisfaction, challenges"
}
}

Parameters

  • op (string, required): Must be "xai.sentiment"
  • content (string, required): The text content to analyze
  • options (object, optional): Analysis configuration
    • analysis_depth (string): Level of detail ("brief", "standard", "detailed")
    • specific_aspects (string): Comma-separated aspects to focus on

Response

{
"data": {
"output": {
"overall_sentiment": "positive",
"sentiment_score": 0.78,
"emotional_indicators": {
"excitement": 0.85,
"satisfaction": 0.82,
"concern": 0.23,
"confidence": 0.76
},
"aspect_sentiments": {
"product quality": {
"sentiment": "very positive",
"score": 0.91
},
"team performance": {
"sentiment": "positive",
"score": 0.87
},
"customer satisfaction": {
"sentiment": "positive",
"score": 0.83
},
"challenges": {
"sentiment": "neutral",
"score": 0.45
}
},
"key_phrases": ["exceeded expectations", "incredibly hard", "overwhelmingly positive"],
"tone_analysis": "optimistic and professional with acknowledgment of areas for improvement"
}
},
"meta": {
"analysis_confidence": 0.94,
"processing_time_ms": 1240
}
}

Use Cases

Product Reviews:

{
"op": "xai.sentiment",
"content": "[Customer product review...]",
"options": {
"analysis_depth": "detailed",
"specific_aspects": "quality, price, delivery, customer service, value for money"
}
}

Social Media Monitoring:

{
"op": "xai.sentiment",
"content": "[Social media posts about brand...]",
"options": {
"analysis_depth": "standard",
"specific_aspects": "brand perception, product mentions, service experience"
}
}

Employee Feedback:

{
"op": "xai.sentiment",
"content": "[Employee survey responses...]",
"options": {
"analysis_depth": "detailed",
"specific_aspects": "job satisfaction, management, work environment, compensation, career development"
}
}

5. Extract Information

POST xai.extract

Extract specific entities, information, and structured data from unstructured text content.

Request Body

{
"op": "xai.extract",
"content": "John Smith, CEO of TechCorp Inc., announced today that the company will be opening a new headquarters in San Francisco, California. The $50 million facility is expected to create 500 new jobs by December 2024. The announcement was made during a press conference at 2:30 PM PST. Contact information: john.smith@techcorp.com, phone: (555) 123-4567.",
"options": {
"entity_types": "people, organizations, locations, dates, contact_info, financial_amounts, job_numbers"
}
}

Parameters

  • op (string, required): Must be "xai.extract"
  • content (string, required): The text content to analyze
  • options (object, optional): Extraction configuration
    • entity_types (string): Comma-separated types of entities to extract

Response

{
"data": {
"output": {
"people": [
{
"name": "John Smith",
"title": "CEO",
"organization": "TechCorp Inc."
}
],
"organizations": [
{
"name": "TechCorp Inc.",
"type": "company"
}
],
"locations": [
{
"city": "San Francisco",
"state": "California",
"type": "headquarters_location"
}
],
"dates": [
{
"date": "December 2024",
"context": "job creation deadline"
},
{
"time": "2:30 PM PST",
"context": "press conference time"
}
],
"contact_info": [
{
"email": "john.smith@techcorp.com",
"phone": "(555) 123-4567"
}
],
"financial_amounts": [
{
"amount": "$50 million",
"context": "facility cost"
}
],
"job_numbers": [
{
"number": "500",
"context": "new jobs to be created"
}
]
}
},
"meta": {
"entities_found": 8,
"extraction_confidence": 0.96,
"processing_time_ms": 1580
}
}

Use Cases

Contract Analysis:

{
"op": "xai.extract",
"content": "[Legal contract text...]",
"options": {
"entity_types": "parties, dates, financial_terms, obligations, deadlines, penalties"
}
}

Resume Parsing:

{
"op": "xai.extract",
"content": "[Resume content...]",
"options": {
"entity_types": "skills, experience, education, certifications, contact_info, employment_history"
}
}

News Analysis:

{
"op": "xai.extract",
"content": "[News article...]",
"options": {
"entity_types": "people, organizations, locations, events, dates, financial_data"
}
}

6. Translate Content

POST xai.translate

Translate text content between languages with style and context preservation.

Request Body

{
"op": "xai.translate",
"content": "We are excited to announce the launch of our new product line. Our innovative solutions will help businesses streamline their operations and improve efficiency. For more information, please visit our website or contact our sales team.",
"options": {
"target_language": "Spanish",
"translation_style": "business-formal"
}
}

Parameters

  • op (string, required): Must be "xai.translate"
  • content (string, required): The text content to translate
  • options (object, required): Translation configuration
    • target_language (string, required): Target language (e.g., "Spanish", "French", "German", "Japanese")
    • translation_style (string, optional): Style preference ("formal", "casual", "technical", "marketing")

Response

{
"data": {
"output": "Nos complace anunciar el lanzamiento de nuestra nueva línea de productos. Nuestras soluciones innovadoras ayudarán a las empresas a optimizar sus operaciones y mejorar la eficiencia. Para obtener más información, visite nuestro sitio web o póngase en contacto con nuestro equipo de ventas."
},
"meta": {
"source_language": "English",
"target_language": "Spanish",
"translation_confidence": 0.98,
"style_applied": "business-formal",
"processing_time_ms": 1120
}
}

Use Cases

Website Localization:

{
"op": "xai.translate",
"content": "[Website content...]",
"options": {
"target_language": "French",
"translation_style": "marketing"
}
}

Customer Support:

{
"op": "xai.translate",
"content": "[Customer inquiry in foreign language...]",
"options": {
"target_language": "English",
"translation_style": "formal"
}
}

Technical Documentation:

{
"op": "xai.translate",
"content": "[Technical manual...]",
"options": {
"target_language": "German",
"translation_style": "technical"
}
}

7. Vectorize Content

POST xai.vectorize

Convert text content into high-dimensional vector embeddings for semantic search and similarity analysis.

Request Body

{
"op": "xai.vectorize",
"content": "Machine learning algorithms can automatically identify patterns in large datasets and make predictions based on historical data.",
"options": {}
}

Parameters

  • op (string, required): Must be "xai.vectorize"
  • content (string, required): The text content to convert to vectors
  • options (object, optional): Vectorization configuration (reserved for future use)

Response

{
"data": {
"output": {
"vector": [0.0234, -0.1567, 0.2891, 0.0945, -0.3421, 0.1876, ...],
"dimensions": 1536,
"model_version": "text-embedding-v2.0"
}
},
"meta": {
"content_length": 119,
"processing_time_ms": 450,
"vector_norm": 1.0
}
}

Use Cases

Semantic Search:

// Vectorize search query and documents for similarity matching
const queryVector = await vectorizeContent("find machine learning tutorials");
const docVectors = await Promise.all(
documents.map(doc => vectorizeContent(doc.content))
);

Content Recommendation:

// Find similar content based on vector similarity
const articleVector = await vectorizeContent(currentArticle.content);
// Compare with other article vectors to find recommendations

Clustering and Analysis:

// Group similar content together
const contentVectors = await Promise.all(
textSamples.map(text => vectorizeContent(text))
);
// Use vectors for clustering analysis

Response Format

All XAI API endpoints return a consistent response structure:

{
"data": {
"output": "..." // The main result of the operation
},
"meta": {
// Operation-specific metadata
"processing_time_ms": 1500,
"confidence": 0.95,
"model_version": "xai-v2.1"
}
}

Error Responses

Common error scenarios and their responses:

Content Too Long

{
"error": {
"code": "CONTENT_TOO_LONG",
"message": "Content exceeds maximum length limit",
"details": {
"max_length": 50000,
"provided_length": 52000
}
}
}

Invalid Language Code

{
"error": {
"code": "INVALID_LANGUAGE",
"message": "Unsupported target language",
"details": {
"provided_language": "Klingon",
"supported_languages": ["Spanish", "French", "German", "Japanese", "Chinese", "Portuguese", "Italian", "Russian"]
}
}
}

Processing Failed

{
"error": {
"code": "PROCESSING_FAILED",
"message": "AI processing encountered an error",
"details": {
"error_type": "model_timeout",
"retry_recommended": true
}
}
}

Common Error Codes

CodeDescriptionResolution
CONTENT_TOO_LONGContent exceeds length limitsReduce content size or split into smaller chunks
CONTENT_EMPTYNo content providedEnsure content field is not empty
INVALID_LANGUAGEUnsupported language codeUse supported language codes
PROCESSING_FAILEDAI model processing errorRetry request or contact support
QUOTA_EXCEEDEDAPI usage quota reachedUpgrade plan or wait for quota reset
INVALID_OPTIONSMalformed options objectCheck options format and values

Best Practices

Content Optimization

  • Keep content concise and well-structured for better AI processing
  • Use clear, grammatically correct text for optimal results
  • Break very long content into smaller, manageable chunks
  • Provide context when needed for domain-specific content

Performance

  • Cache results for frequently processed content
  • Use appropriate content lengths based on your use case
  • Batch similar operations when possible
  • Monitor processing times and adjust accordingly

Quality Assurance

  • Review AI outputs before using in production
  • Implement human oversight for critical applications
  • Test with diverse content types during development
  • Monitor confidence scores and adjust thresholds as needed

Security

  • Sanitize user inputs before processing
  • Avoid sending sensitive or personal information
  • Implement appropriate access controls
  • Log and monitor API usage patterns

The XAI API empowers your applications with advanced AI capabilities, enabling intelligent content processing, analysis, and generation that can transform user experiences and business operations.