Chapter 5: Phase 2 - API Interface

REST API endpoints for consciousness measurement services

5.1 Base Configuration

Base URL: https://api-wialive.smilestory.ai/consciousness/v1

Authentication:
  - Bearer Token (JWT)
  - API Key (X-WIA-API-Key header)

5.2 Core Endpoints

Measurement Endpoints

POST /measure

Initiate a new consciousness measurement session

Request:
{
  "subject_id": "uuid",
  "method": "TMS-EEG",
  "parameters": {
    "tms_intensity": 80,
    "pulse_count": 200
  }
}

Response:
{
  "measurement_id": "uuid",
  "status": "initiated",
  "estimated_duration": 1200
}
GET /measure/{measurement_id}

Retrieve measurement results

Response:
{
  "consciousness_index": { ... },
  "status": "completed",
  "timestamp": "2025-01-15T10:30:00Z"
}

State Endpoints

GET /state/{subject_id}

Get current consciousness state for a subject

Response:
{
  "subject_id": "uuid",
  "state": {
    "condition": "MCS_plus",
    "arousal_level": 0.45,
    "awareness_level": 0.38
  },
  "last_updated": "2025-01-15T10:30:00Z"
}
PUT /state/{subject_id}

Update consciousness state (clinical use)

PCI Endpoints

GET /pci/{subject_id}

Get PCI measurement for a subject

Response:
{
  "subject_id": "uuid",
  "pci": {
    "value": 0.48,
    "classification": "MCS_plus",
    "threshold_status": "above"
  },
  "complexity_measures": {
    "lempel_ziv": 0.72,
    "entropy": 0.68
  }
}

Phi (Φ) Endpoints

GET /phi/{subject_id}

Get integrated information (Φ) estimate

Response:
{
  "phi_estimate": {
    "value": 2.5,
    "unit": "bits",
    "method": "approximation"
  },
  "iit_metrics": { ... }
}

Theory Comparison

POST /compare

Compare IIT and GNW theory predictions

Request:
{
  "measurement_id": "uuid",
  "theories": ["IIT", "GNW"]
}

Response:
{
  "comparisons": [
    {
      "theory": "IIT",
      "predictions": [...],
      "overall_support": 0.72
    },
    {
      "theory": "GNW",
      "predictions": [...],
      "overall_support": 0.58
    }
  ]
}

AI Assessment

POST /ai/assess

Assess consciousness indicators in an AI system

Request:
{
  "system_id": "gpt-4",
  "system_type": "LLM",
  "model_info": {
    "name": "GPT-4",
    "parameters": 1.8e12
  }
}

Response:
{
  "indicators": { ... },
  "overall_assessment": {
    "consciousness_likelihood": "uncertain",
    "confidence": 0.45
  }
}

5.3 Real-time Monitoring

WebSocket endpoint for continuous monitoring:

WebSocket: wss://api-wialive.smilestory.ai/consciousness/v1/monitor/{subject_id}

Subscribe Message:
{
  "action": "subscribe",
  "metrics": ["pci", "phi", "state"]
}

Update Events:
{
  "timestamp": "2025-01-15T10:30:00Z",
  "pci": 0.45,
  "phi_estimate": 2.3,
  "state": "MCS_plus",
  "alert": {
    "type": "threshold_crossed",
    "message": "PCI dropped below 0.40"
  }
}

5.4 Rate Limits

Endpoint CategoryRate LimitBurst
Measurement10/min20
State Queries60/min100
PCI/Phi Queries30/min50
AI Assessment5/min10

5.5 SDK Usage Example

import { ConsciousnessClient } from '@wia/consciousness';

const client = new ConsciousnessClient({
  apiKey: 'your-api-key'
});

// Measure consciousness
const measurement = await client.measure({
  subject_id: 'patient-001',
  method: 'TMS-EEG'
});

// Get PCI
const pci = await client.getPCI(measurement.id);
console.log(`PCI: ${pci.value}, State: ${pci.classification}`);

// Real-time monitoring
client.monitor('patient-001', (update) => {
  if (update.alert) {
    console.warn(update.alert.message);
  }
});