Create guardrails and assign them to your API keys — budgets, model and provider lists, and content filters.
A guardrail is a set of rules you put on your API keys: a budget in DA, the models that may run, the providers that may serve, zero data retention per lab, and content filters. It binds only the keys it is assigned to.
Every guardrail route is free and takes a management key. The openai SDK has no guardrails resource, so call the routes with fetch.
const headers = {
Authorization: `Bearer ${process.env.OPENDUNES_MANAGEMENT_KEY}`,
"Content-Type": "application/json",
};
const res = await fetch("https://opendunes.com/v1/guardrails", {
method: "POST",
headers,
body: JSON.stringify({
name: "Souk Bot production",
limit: 500, // budget in DA
reset_interval: "monthly",
allowed_models: ["anthropic/claude-sonnet-5"],
content_filter_builtins: [{ slug: "email", action: "redact" }],
}),
});
const { data: guardrail } = await res.json(); // 201Keys are named by their hash — the hash the API keys routes return.
await fetch(`https://opendunes.com/v1/guardrails/${guardrail.id}/assignments/keys`, {
method: "POST",
headers,
body: JSON.stringify({ key_hashes: [keyHash] }),
});
// → { assigned_count: 1 }…/assignments/keys/remove takes the same body and unassigns.
A request the guardrail blocks fails before it reaches a model, and nothing is charged:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://opendunes.com/v1",
apiKey: process.env.OPENDUNES_API_KEY,
});
try {
await client.chat.completions.create({
model: "openai/gpt-5.6-luna", // not in allowed_models
messages: [{ role: "user", content: "Marhba!" }],
});
} catch (err) {
if (err instanceof OpenAI.APIError) console.log(err.status);
// 403 — blocked; 402 with limit_source "guardrail" once the budget is spent
}