Your account through a management key
Run your account from a script: read the balanceBalanceWhat you can spend, in DA.More on Balance and charges →, then manage your keys.
1. Make a management key
Create one in your dashboard, under Settings then Management keysManagement keyThe key that runs your account through the API: the balance, the usage history, your keys, guardrails, observability. It never calls a model.More on API keys →. Its secret shows once: put it in the environment as OPENDUNES_MANAGEMENT_KEY and keep it out of the code.
A management key runs the account and never calls a model. An API keyAPI keyThe key you create and send with every request that calls a model.More on API keys → is the reverse: it calls models and gets a 401 on every account route in this guide. Keep one of each, so a script that reads the balance cannot spend it. The two compared: API keys.
A management key's expiry is fixed when you create it, and it cannot be changed after. Choose the span with the script in mind, and make a new key before the old one runs out.
2. Read your balance
GET /v1/credits answers two totals in DADAThe Algerian dinar, the one currency the docs show.More on Balance and charges →: what came into your wallet, and what requests spent. This sample prints what is left, as Souk Bot's owner in Oran would check it each morning.
import json
import os
import urllib.request
MANAGEMENT_KEY = os.environ["OPENDUNES_MANAGEMENT_KEY"]
ADDRESS = "https://opendunes.com/v1/credits"
request = urllib.request.Request(
ADDRESS,
headers={"Authorization": "Bearer " + MANAGEMENT_KEY},
)
with urllib.request.urlopen(request) as response:
totals = json.load(response)["data"]
left = totals["total_credits"] - totals["total_usage"]
print("DA left:", left)The answer holds total_credits and total_usage under data, both in DA. Your balance is the first minus the second. Reading it is free, however often a script does.
Every account route is free to call. Running a model is what is billed, and a management key cannot.
3. List and create API keys
The same key manages your API keys. GET /v1/keys lists them, 100 to a page, oldest first. POST /v1/keys creates one from a name, and answers its secret once, in key.
| Do | Send |
|---|---|
| list keys | GET /v1/keys, with include_disabled=true to list paused keys too |
| create a key | POST /v1/keys with a name, and if you want one a cap, a reset and an expiry |
| pause or change a key | PATCH /v1/keys/{hash} |
| delete a key | DELETE /v1/keys/{hash}: a request sent with it gets a 401 from then on |
The fields of each route, with a sample: Keys.
Create one API key for each app, with its own cap, so a runaway loop in one app stops at its cap and the others keep working.
Don't put the management key in a browser page or a mobile app. It can create and delete keys; anyone who reads it runs your account.
4. See what else it runs
| To | Use | Reference |
|---|---|---|
| read the balance | GET /v1/credits | Balance |
| read the usage history | GET /v1/activity | Usage history |
| manage API keys | /v1/keys | Keys |
| write rules for what a request may do | /v1/guardrails | Guardrail rules |
| send traces to your own tool | /v1/observability/destinations | Trace destinations |
| share a wallet | /v1/workspaces | Workspaces |
Errors
The body says why. What to do on every status: Errors and retries.
| Status | Means |
|---|---|
| 401 | the management key is missing, wrong, revoked or expired, or it is an API key |
| 404 | no key, rule, destination or workspace of yours has that address |