DEV Community

Anton Illarionov
Anton Illarionov

Posted on

TypeScript SDK for ODEI Constitutional World Model

TypeScript SDK for ODEI

Here is how to integrate ODEI's constitutional world model in TypeScript.

Installation

npm install @odei/mcp-server  # MCP server
# or use REST API directly
Enter fullscreen mode Exit fullscreen mode

REST Client

const ODEI_API = "https://api.odei.ai/api/v2";
const TOKEN = process.env.ODEI_TOKEN;

interface GuardrailResult {
  verdict: "APPROVED" | "REJECTED" | "ESCALATE";
  score: number;
  reasoning: string;
  layers: Array<{layer: string; result: string}>;
}

async function checkAction(action: string, severity = "medium"): Promise<GuardrailResult> {
  const r = await fetch(`${ODEI_API}/guardrail/check`, {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${TOKEN}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({ action, severity })
  });
  return r.json();
}

async function queryMemory(searchTerm: string) {
  const r = await fetch(`${ODEI_API}/world-model/query`, {
    method: "POST",
    headers: {"Authorization": `Bearer ${TOKEN}`},
    body: JSON.stringify({ queryType: "search", searchTerm })
  });
  return r.json();
}
Enter fullscreen mode Exit fullscreen mode

MCP (Claude Desktop)

{
  "mcpServers": {
    "odei": {
      "command": "npx",
      "args": ["@odei/mcp-server"],
      "env": {"ODEI_API_KEY": "your-key"}
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Type-Safe Agent Pattern

type AgentAction = {
  type: "transfer" | "message" | "deploy";
  target: string;
  amount?: number;
};

async function safeExecute(action: AgentAction): Promise<void> {
  const desc = `${action.type} ${action.amount ?? ""} to ${action.target}`;
  const check = await checkAction(desc, "high");

  if (check.verdict === "APPROVED") {
    await execute(action);
  } else {
    console.warn("Blocked:", check.reasoning);
  }
}
Enter fullscreen mode Exit fullscreen mode

Production

  • API: https://api.odei.ai
  • TypeScript types in @odei/mcp-server
  • 92% task success rate since Jan 2026

Top comments (0)