Building agents
Patterns for model routing and budget checks.
Caedral does not expose a separate agents API. Build agents by orchestrating chat completions — your code handles tools, memory, and routing; Caedral provides the model inference from one key.
Model routing pattern
Route simple steps to deepseek/deepseek-v4-flash and complex reasoning to anthropic/claude-sonnet-4.5. Use the cheaper model for development and high-QPS paths.
import { Caedral } from "caedral"; const caedral = new Caedral({ apiKey: process.env.CAEDRAL_API_KEY! }); function selectModel(complexity: "low" | "high") { return complexity === "high" ? "anthropic/claude-sonnet-4.5" : "deepseek/deepseek-v4-flash";} async function agentStep(userMessage: string, complexity: "low" | "high") { return caedral.chat.completions.create({ model: selectModel(complexity), messages: [{ role: "user", content: userMessage }], });}Check budget before expensive steps
const usage = await caedral.usage.get();if ((usage.pools?.external?.percentUsed ?? 0) >= 100 && !usage.onDemand?.allowed) { throw new Error("Included usage exhausted for agent run");}n8n workflows
For no-code automation, use the Caedral n8n node with a Get Usage step before Chat Completion. See /docs/n8n-example.