Back to Guides & Cookbooks
Cookbook
How to turn any REST API into a governed AI tool
Upload an OpenAPI spec. Cadreen auto-generates governed tools from every endpoint — credential-aware, failure-classified, health-checked.
1
Register your OpenAPI spec
One call. Cadreen reads the spec, generates tool definitions for every endpoint, and registers them in the capability graph.
TypeScript
const connection = await cadreen.connections.registerOpenAPI({
name: "Invoicing API",
spec_url: "https://api.example.com/openapi.json",
credentials: {
type: "bearer",
token: "inv_sk_...",
},
});
console.log(connection.tools_count); // 15
console.log(connection.id); // "conn_abc123"Python
connection = await cadreen.connections.register_open_api(
name="Invoicing API",
spec_url="https://api.example.com/openapi.json",
credentials={
"type": "bearer",
"token": "inv_sk_...",
},
)
print(connection.tools_count) # 15
print(connection.id) # "conn_abc123"OpenAPI spec → Cadreen auto-generates governed tools for every endpoint
2
Use the tools from any surface
The tools are now available to the model in any conversation. Ask in natural language — Cadreen routes to the right tool.
opencode, SDK, or any chat surface
> Create an invoice for $500 for Acme Corp, due in 30 days
[Calling create_invoice(amount: 500, customer: "Acme Corp", due_days: 30)]
Invoice created: inv_abc123 for $500, due July 21.Discover available tools
const tools = await cadreen.chat.listTools();
// Returns OpenAI function definitions — ready to use in any request
console.log(tools[0]);
// {
// type: "function",
// function: {
// name: "create_invoice",
// description: "Create a new invoice",
// parameters: { type: "object", properties: { ... } }
// }
// }Note
Tools are health-checked and failure-classified. If a tool goes down, Cadreen routes around it automatically.
3
Or register an MCP server
If you have an MCP (Model Context Protocol) server, register it the same way. Cadreen probes /.well-known/mcp and discovers tools automatically.
TypeScript
const connection = await cadreen.connections.registerMCP({
name: "Internal Tools",
url: "https://mcp.internal.example.com",
credentials: {
type: "bearer",
token: "mcp_sk_...",
},
});Note
Next: How to audit every AI decision with intelligence traces — hash-chained, tamper-detectable.