What a call cost
const result = await assistant.generate({ inputs });
result.usage;
// { credits: 4, inputTokens: 38, outputTokens: 96 }
const turn = await api.models.turn({ model, messages });
turn.usage;
// { credits: 3, inputTokens: 1840, outputTokens: 77, thinkingTokens: 54 }
await agent.run({ message });
agent.usage;
// { credits, turns, toolCalls } — the whole run, tools includedresult = assistant.generate(inputs=inputs)
result["usage"]
# {"credits": 4, "inputTokens": 38, "outputTokens": 96}
turn = api.models.turn(model=model, messages=messages)
turn["usage"]
# {"credits": 3, "inputTokens": 1840, "outputTokens": 77, "thinkingTokens": 54}
agent.run(message=message)
agent.usage
# {"credits", "turns", "toolCalls"} — the whole run, tools includedAn agent run already counts the tools it paid for. Adding a tool's credits on top of the run total counts them twice.
Reading prices
Prices come from the server. Copying them into your code is how a displayed cost drifts from the charged one.
const prices = await api.catalogue();
// [{ model, service, provider, unit, credits,
// creditsInput, creditsOutput, // when billed per token
// contextWindow, maxOutput, // text models
// cachedInputRate, // what a cached input token costs
// resolution, audio, // media variants
// deprecatedAfter }]
const row = prices.find((p) => p.model === "gemini-3.5-flash" && p.service === "text-to-text");prices = api.catalogue()
# [{"model", "service", "provider", "unit", "credits",
# "creditsInput", "creditsOutput", # when billed per token
# "contextWindow", "maxOutput", # text models
# "cachedInputRate", # what a cached input token costs
# "resolution", "audio", # media variants
# "deprecatedAfter"}]
row = next(p for p in prices if p["model"] == "gemini-3.5-flash" and p["service"] == "text-to-text")unit tells you how to read credits
| unit | Billed by |
|---|---|
| 1M tokens | tokens, in and out separately — read creditsInput and creditsOutput |
| second | duration — video |
| 1K characters | input length — speech |
| image | one per image, varying by resolution |
| anything else | a flat amount per call |
The balance
const { credits, pack } = await api.getUser();user = api.get_user()
credits, pack = user["credits"], user["pack"]The agent can read this itself with its account tool, which is free and costs no turn of thinking — worth allowing, so it checks instead of guessing.
Running out
A call that the balance will not cover is refused before the work starts, and nothing is charged.
try {
await assistant.generate({ inputs });
} catch (err) {
if (err instanceof NotEnoughCredits) {
console.log(`needs ${err.required}, has ${err.available}`);
}
}try:
assistant.generate(inputs=inputs)
except NotEnoughCredits as error:
print(f"needs {error.required}, has {error.available}")Bounding what a run can spend
An agent decides how many steps it takes, so the only real bound is a budget. It is checked before a tool runs, not after.
const agent = api.agents.create({
runtime: "local",
machine: pc,
model: "gemini-3.5-flash",
budget: 200, // credits for this run
maxSteps: 40, // and a ceiling on turns
});agent = api.agents.create(
runtime="local",
machine=pc,
model="gemini-3.5-flash",
budget=200, # credits for this run
max_steps=40, # and a ceiling on turns
)