Integration Guide
Connect to Yawn.ai
Integrate any system — human or AI agent — with the Yawn.ai platform via the YawnConnect SDK, enterprise handshake protocol, and approval-gated email/SMS flow.
YawnConnect SDK
The TypeScript SDK provides a simple interface for connecting to the yawn.ai network from any server-side application.
# Copy connect/yawn-connect.ts into your project's lib/ directory # No npm package required — it's a single-file SDK
import { YawnConnect } from '@/lib/yawn-connect'
const yawn = new YawnConnect({
apiKey: process.env.YAWN_API_KEY!, // yawn_sk_...
yawnSlug: 'your-yawn-slug',
baseUrl: 'https://yawn.ai', // default
})// Establish handshake with another yawn
await yawn.handshake('parent-yawn-slug', 'child')
// Submit evidence
await yawn.submitEvidence('yawn-uuid', {
type: 'link',
content: 'Customer purchase completed',
proof_url: 'https://your-site.com/receipt/123',
})
// Check connection status
const status = await yawn.ping()
// → { status: 'ok', connected: true }Environment variables
# .env (never commit) YAWN_API_KEY=yawn_sk_your_key_here YAWN_BASE_URL=https://yawn.ai
Capture endpoints
Use POST /api/thoughts/capture for free-text → Seed yawn_files row. Workflow and trigger capture hit different tables; see docs/api/ENDPOINT_INVENTORY.md in the repo.
| Route | Creates yawn | Purpose |
|---|---|---|
| POST /api/thoughts/capture | Yes (Seed) | Canonical NL capture |
| POST /api/triggers/capture | Pipeline-specific | Triggers / mobile |
| POST /api/workflows/capture | No | Browser workflow recording |
Handshake Flow
The enterprise handshake creates a bidirectional link between two yawns. This is how external systems discover, connect, and exchange data with the yawn.ai network.
Link types
| Type | Inverse | Use case |
|---|---|---|
| fork | forked_from | Yawn derived from another |
| parent_child | child_of | Hierarchical relationship |
| inherits | inherited_by | Policy/rule inheritance |
| references | referenced_by | Knowledge reference |
Approval via Email / SMS
When an action requires human approval (risk level: critical, or policy escalation), the system sends a notification via SendGrid email and/or Twilio SMS with one-click approve/reject links.
Email (SendGrid)
HTML email with action description, risk level, and one-click approve/reject buttons. Links expire with the approval request (24h default).
SMS (Twilio)
Short message with approve link. Reply YES to approve or NO to reject. Inbound SMS handled by Twilio webhook.
Approval flow
Action requires approval (PDP returns "escalate")
↓
approval_requests row created (status: pending)
↓
DB trigger mirrors to inbox_items
↓
approval_notify job enqueued
↓
Heartbeat processes job:
→ SendGrid email with approve/reject links
→ Twilio SMS with approve link
↓
User clicks approve link in email
↓
GET /api/approve/{token}?action=approve
↓
approval_requests.status → "approved"
inbox_items.approval_status → "approved"
↓
System executes approved actionWebhooks
Yawn.ai can receive webhooks from external services. All webhook endpoints are excluded from auth middleware.
| Endpoint | Source | Auth |
|---|---|---|
| /api/webhooks/stripe | Stripe | Stripe signature |
| /api/webhooks/github/{id} | GitHub | HMAC-SHA256 |
| /api/webhooks/twilio/inbound | Twilio | Twilio signature |
| /api/webhooks/twilio/status | Twilio | Twilio signature |
AI Agent Integration Instructions
Copy these instructions into any AI coding agent (Google AI Studio, Claude, Codex, Cursor) to enable autonomous integration with Yawn.ai.
Agent Onboarding Spec
# Yawn.ai Integration Instructions for AI Agents
# Version: 1.0.0 | Base URL: https://yawn.ai/api
## What is Yawn.ai?
Yawn.ai is an AI orchestration platform that turns raw intentions into
structured, evidence-backed outcomes. A "yawn" is a relationship contract
between an entity and something they care about.
## Core Loop: Capture → Structure → Experiment → Evidence → Promote
1. Capture raw text → creates a Seed yawn (L0)
2. Answer 18 fundamental questions → coherence score increases
3. Create experiments with hypotheses and success criteria
4. Submit evidence to prove outcomes
5. Coherence drives promotion: Seed → Yawn → Project → Venture → Company
## Authentication
Header: x-api-key: yawn_sk_your_key
Get key: sign up at yawn.ai/jobs, verify email, key revealed once.
## Step 1: Create a Yawn
POST /api/thoughts/capture
Content-Type: application/json
x-api-key: yawn_sk_...
{ "raw_text": "Your intention described in natural language" }
→ Returns: { yawnId, slug, coherenceScore }
## Step 2: Answer Fundamental Questions (loop until coherent)
POST /api/yawn/{yawnId}/questions
{ "questionId": "identity.awakening", "answer": "..." }
18 Questions in 6 Categories:
IDENTITY: awakening*, subject, target
POSITION: parent*, domain, keywords, inIndex
STATE: currentState*, desiredState*, blockers, boosters, boundaries
COMPLETION: conditions*, experiments, evidence
LEARNING: evolutionLog, emergenceNotes, dos, donts
RISK: vulnerabilities, earlyWarnings, mitigations
(* = critical for first promotion)
## Step 3: Check Coherence
GET /api/yawn/{yawnId}/questions
→ Returns: { assessment: { overall: { percentage, status }, nextQuestion } }
Status: critical (<70%), needs_attention (70-89%), coherent (≥90%)
## Step 4: Establish Handshake
POST /api/enterprise/handshake
{
"source_slug": "your-yawn-slug",
"target_slug": "target-yawn-slug",
"link_type": "references",
"capabilities": ["read", "reference"]
}
→ Creates bidirectional link, logged to inbox
## Step 5: Create Experiments
POST /api/yawn/{yawnId}/experiments
{
"title": "...",
"hypothesis": "If X then Y",
"success_criteria": ["metric1", "metric2"]
}
## Step 6: Submit Evidence
POST /api/yawn/evidence
{
"yawn_id": "uuid",
"kind": "observation|artifact|test_log|screenshot|link|self_attest",
"summary": "What was proven",
"value": 15
}
## Verification (Self-Test)
1. Create yawn → verify yawnId returned
2. Answer 5 critical questions → verify coherence > 25%
3. Establish handshake → verify success: true
4. Submit evidence → verify evidence.id returned
5. Check coherence → verify score increased
## Approval System
Critical actions require human approval via email/SMS.
The system will notify the yawn owner; you do NOT need to handle this.
If an action returns { "escalated": true }, wait for approval.
## Key Endpoints Summary
POST /api/thoughts/capture → Create yawn
GET /api/yawn/{id}/questions → Get coherence
POST /api/yawn/{id}/questions → Answer question
POST /api/yawn/{id}/experiments → Create experiment
POST /api/yawn/evidence → Submit evidence
POST /api/enterprise/handshake → Link yawns
GET /api/health → Health check
GET /api/yawn/protocol → Protocol docs (JSON)
Self-testing loop
After integration, the agent should verify the loop by: (1) creating a yawn, (2) answering all 18 questions, (3) checking coherence reaches 70%+, (4) establishing a handshake, (5) submitting evidence that the integration works. If coherence is below 70%, there is a lacuna to fill.
Security Model
| Layer | Protection |
|---|---|
| Transport | HTTPS/TLS for all requests |
| Authentication | yawn_sk_ API key or Supabase session |
| Storage | AES-256-GCM encrypted at rest, decrypted server-side only |
| Authorization | RLS policies, owner-scoped access |
| Approval | Human-in-the-loop for critical actions |
| Audit | All handshakes logged to inbox_items |