Back to Home

API Technical Documentation

Complete reference for integrating with the AFFECTIVELY REST API

Getting Started

Base URL

All API requests should be made to:

https://affectively.com/api

Authentication

The AFFECTIVELY API uses Firebase Authentication. Include your Firebase Auth token in the Authorization header:

Authorization: Bearer YOUR_FIREBASE_AUTH_TOKEN

To obtain a Firebase Auth token, authenticate through the AFFECTIVELY web application or use the Firebase SDK.

Rate Limiting

Rate limits are enforced per subscription tier to ensure fair usage and system stability. All rate limits are applied per user (identified by Firebase Auth token). Limits are calculated to maintain sustainable service costs while providing reasonable usage allowances.

Rate Limit Tiers

Rate limits are enforced at three levels: per minute, per hour, and per day. The most restrictive limit applies. Daily limits are the primary control for monthly usage.

Free Tier~3,000 requests/month
  • • 5 requests per minute
  • • 30 requests per hour
  • • 100 requests per day
Premium Tier~1,800 requests/month
  • • 10 requests per minute
  • • 30 requests per hour
  • • 60 requests per day

Premium subscription: $9.99/month

Ultra-Premium Tier~5,500 requests/month
  • • 15 requests per minute
  • • 50 requests per hour
  • • 183 requests per day

Ultra-Premium subscription: $29.99/month

API Tier~1,500,000 requests/month
  • • 100 requests per minute
  • • 5,000 requests per hour
  • • 50,000 requests per day

For enterprise API access, contact us for pricing

How Rate Limits Work

Rate limits are enforced at three time windows simultaneously. All three limits must be satisfied:

  • Per Minute: Prevents burst traffic and ensures smooth operation
  • Per Hour: Controls medium-term usage patterns
  • Per Day: Primary limit that controls monthly usage and costs

If you exceed any limit, you'll receive a 429 error. The daily limit is typically the most restrictive for normal usage patterns.

Rate Limit Headers

Every API response includes rate limit information in the response headers:

  • X-RateLimit-Limit: Your tier's limit
  • X-RateLimit-Remaining: Remaining requests in the current window
  • X-RateLimit-Reset: Unix timestamp when the limit resets
  • Retry-After: Seconds to wait before retrying (when rate limited)

Rate Limit Exceeded

When you exceed your rate limit, you'll receive a 429 Too Many Requests response:

{ "error": "Rate limit exceeded", "message": "You have exceeded the rate limit for your subscription tier...", "rateLimit": { "limit": 5, "remaining": 0, "resetAt": "2024-01-15T10:31:00.000Z" } }

Wait until the reset time before making additional requests. Consider upgrading your subscription tier for higher limits.

Request Format

All requests should:

  • • Use HTTPS (required in production)
  • • Include Content-Type: application/json header for POST requests
  • • Send JSON-encoded request bodies
  • • Include authentication token in Authorization header

Response Format

All responses:

  • • Return JSON-encoded data
  • • Include appropriate HTTP status codes
  • • Include rate limit headers (see above)
  • • Follow a consistent error format (see Error Handling)

API Endpoints

Emotions API

GET/api/emotions

List all emotions with optional filtering. No authentication required.

Query Parameters:

  • level: 'primary' | 'secondary' | 'tertiary' | 'all' (default: 'all')
  • valence: 'positive' | 'negative' | 'neutral'
  • arousal: 'low' | 'moderate' | 'high'
  • ekmanCategory: Filter by Ekman category
  • search: Text search in name/description
GET https://affectively.com/api/emotions?level=primary&valence=positive
GET/api/emotions/hierarchy

Get the complete emotion hierarchy (primary → secondary → tertiary). No authentication required.

GET/api/emotions/[id]

Get details for a specific emotion by ID. No authentication required.

Text Analysis API

POST/api/text/analyzeRequires Auth

Analyzes text for emotions and infers psychological profiles. Requires API subscription tier.

Request Body:

{ "text": "string", "options": { "includeFullAIC": boolean } }

Response:

TextAnalysisResponse with emotions, CVM facts, psychological profile

AIC (Affective Intelligence Companion) API

POST/api/aic/analyzeRequires Auth

Client-agnostic API for Affective Intelligence System. Accepts AffectInput and returns AffectOutput. Requires API subscription tier.

Request Body:

AffectInput schema (validated via Zod)

Response:

AffectOutput with Low-Entropy Label and Adaptive Lever

Agent Chat API

POST/api/agent/chatRequires AuthUltra-Premium

Streaming chat endpoint for interacting with an AI agent that has access to MCP tools. The agent can analyze emotions, text, and provide psychological insights using the Affective Intelligence Companion system. Requires Ultra-Premium subscription or admin access.

Request Body:

{ "messages": [ { "role": "user" | "assistant" | "system", "content": "string" } ], "conversationId": "string" // Optional: for resuming conversations }

Response:

Streaming response using AI SDK data stream format. The agent can autonomously call MCP tools during the conversation:

  • analyze_affect - Analyze affective states
  • analyze_text - Analyze text for emotions and psychological insights
  • get_emotions - Query emotion taxonomy
  • generate_repartee - Generate strategic repartee (Ultra-Premium)
  • generate_visual_repartee - Analyze images and generate responses (Ultra-Premium)

Note:

This endpoint uses Server-Sent Events (SSE) for streaming. Use the AI SDK's useChat hook or handle the stream manually. Tool invocations are included in the stream.

Error Handling

All errors follow a consistent format:

{ "error": "Error type", "message": "Human-readable error message", "details": {} // Optional additional error details }

400 Bad Request

Invalid request format or validation failed

401 Unauthorized

Missing or invalid authentication token

403 Forbidden

Valid token but insufficient subscription tier

429 Too Many Requests

Rate limit exceeded (see Rate Limiting section)

500 Internal Server Error

Server-side error occurred

Code Examples

JavaScript/TypeScript

const response = await fetch('https://affectively.com/api/text/analyze', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${firebaseAuthToken}` }, body: JSON.stringify({ text: 'I feel anxious about the upcoming presentation.' }) }); const data = await response.json(); console.log('Remaining requests:', response.headers.get('X-RateLimit-Remaining'));

Python

import requests response = requests.post( 'https://affectively.com/api/text/analyze', headers={ 'Content-Type': 'application/json', 'Authorization': f'Bearer {firebase_auth_token}' }, json={ 'text': 'I feel anxious about the upcoming presentation.' } ) data = response.json() print(f"Remaining requests: {response.headers.get('X-RateLimit-Remaining')}")

cURL

curl -X POST 'https://affectively.com/api/text/analyze' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer YOUR_FIREBASE_AUTH_TOKEN' \ -d '{ "text": "I feel anxious about the upcoming presentation." }'

Additional Resources

MCP Server Documentation

For AI agent integration, see our MCP Server Technical Documentation.

Support

Need help? Visit our Contact page for support.

Subscription

To access authenticated endpoints, you'll need an API subscription. See Pricing for details.