Developer Playground

Code examples and quick-start snippets for building on the Internet of Intelligence

Sending Messages to IOI

Route messages through Nucleus, Jericho, or Genesis operators

import { createSupabaseClient } from '@/lib/supabase';

const supabase = createSupabaseClient();

async function sendMessage() {
  const response = await fetch('/api/operators/chat', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      operator: 'nucleus',
      messages: [
        { role: 'user', content: 'Route this healthcare message' }
      ]
    }),
  });

  const data = await response.json();
  console.log('Operator response:', data.reply);
}

Working with Message Receipts

Retrieve routing receipts and verify message delivery

async function getReceipt(messageId: string) {
  const response = await fetch(`/api/v1/receipts/${messageId}`);
  const receipt = await response.json();

  return {
    messageId: receipt.messageId,
    status: receipt.status,
    envelopeHash: receipt.envelopeHash,
    governanceDecision: receipt.governanceDecision,
    latencyMs: receipt.latencyMs
  };
}

// Usage
const receipt = await getReceipt('msg-abc123');
console.log('Message status:', receipt.status);

Defining a Rail Policy

Create PoHG governance policies for your rails

// Define a simple PoHG policy for healthcare rail
const healthcarePolicy = {
  version: 'v0.0.1',
  rail: 'healthcare',
  rules: [
    {
      name: 'PHI Detection',
      condition: 'dataClassification === "PHI"',
      action: 'vault_encrypt',
      required: true
    },
    {
      name: 'HIPAA Compliance',
      condition: 'regulatoryRegime === "HIPAA"',
      action: 'audit_log',
      required: true
    }
  ],
  governance: {
    harmonyThreshold: 0.75,
    riskThreshold: 0.40,
    validators: 3
  }
};

// Check policy compliance
const response = await fetch('/api/v1/policy/preview', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    policy: healthcarePolicy,
    envelope: yourMessageEnvelope
  })
});

const { compliant, violations } = await response.json();

Using the IOI SDK

Full-featured SDK for TypeScript/JavaScript applications

// Install the IOI SDK
// npm install @ioi/sdk

import { IOIClient } from '@ioi/sdk';

const client = new IOIClient({
  apiKey: process.env.IOI_API_KEY,
  nodeId: process.env.IOI_NODE_ID
});

// Send a message through IOI rails
const message = await client.messages.send({
  rail: 'healthcare',
  destination: 'node-clinic-123',
  payload: {
    type: 'clinical_order',
    patientId: 'patient-456',
    orderId: 'order-789'
  },
  dataClassification: 'PHI'
});

console.log('Message routed:', message.id);
console.log('Receipt:', message.receipt);

Next Steps

Explore the Console

Test operators, inspect governance events, and monitor network activity in real-time.

Open Console →

Read the Protocol Docs

Deep dive into AIIP message envelopes, rail selection, and PoHG governance.

View Documentation →