List, create, change and delete API keys with a management key.
API keys authenticate requests to the OpenDunes API. A default key is created automatically when you sign up; keys look like sk- followed by a random string, and the full value is shown once at creation — only a secure hash is stored.
Programmatic key management goes through /v1/keys. It authenticates with a management key (mk-…) — a separate credential from your API keys, created at Settings → Management Keys; an API key there answers 401. For interactive management, use the Keys page.
A key is named by its hash: the SHA-256 of the key, in lowercase hex. Every amount is in DA.
The openai SDK has no keys resource, so call the endpoints directly with fetch.
const headers = { Authorization: `Bearer ${process.env.OPENDUNES_MANAGEMENT_KEY}` };
const res = await fetch("https://opendunes.com/v1/keys", { headers });
const { data } = await res.json();
// [{ hash, name, label, disabled, limit, limit_remaining, limit_reset, usage, … }, ...] — never the secretActive keys, 100 at a time; add ?offset=100 for the next page and ?include_disabled=true for the disabled ones.
const res = await fetch("https://opendunes.com/v1/keys", {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({
name: "production-backend",
limit: 2000, // optional spending cap in DA
limit_reset: "monthly", // optional: daily, weekly or monthly
}),
});
const { data, key } = await res.json(); // 201
// key is returned ONCE — store it in your secret manager now; data.hash names it from now onawait fetch(`https://opendunes.com/v1/keys/${hash}`, {
method: "PATCH",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ limit: 5000, disabled: false }),
});
// → { data: { … the key, changed … } }PATCH takes name, limit, limit_reset, storage and disabled. A disabled key answers 401 until it is enabled again.
await fetch(`https://opendunes.com/v1/keys/${hash}`, { method: "DELETE", headers });
// → { deleted: true }Requests with a deleted key answer 401. A hash that is not one of your keys is a 404.