N/llm adds async getRemainingUsage.promise() for AI Unit balance checks
The N/llm module now exposes llm.getRemainingUsage.promise(), an asynchronous method for querying remaining AI Units in SuiteScript 2.1 server scripts without blocking execution.
What changed
A new asynchronous method, llm.getRemainingUsage.promise(), has been added to the N/llm module in SuiteScript 2.1 (2026.1). It is the promise-based counterpart to the synchronous llm.getRemainingUsage().
- Returns: a
Promisethat resolves with the number of AI Units remaining on the account. - Governance: None — calling this method does not consume governance units.
- Supported context: Server-side scripts only (Scheduled, Map/Reduce, Suitelet, User Event, RESTlet, etc.).
- Parameters and thrown errors: identical to
llm.getRemainingFreeUsage().
Note the distinction between the two related methods:
llm.getRemainingUsage()/.promise()— returns total remaining AI Units (paid entitlement).llm.getRemainingFreeUsage()/.promise()— returns remaining free-tier AI Units.
Syntax
Because this is a SuiteScript 2.1 promise API, use .then() (or await in an async entry point):
llm.getRemainingUsage.promise().then(function(remaining) {
log.debug('AI Units left', remaining);
});What to do
- Prefer the async variant in long-running scripts. In Map/Reduce or Scheduled scripts where you check AI Unit balance before dispatching LLM calls, use
llm.getRemainingUsage.promise()to avoid blocking the thread. - Guard LLM-heavy workflows. Call this method before expensive
llm.generateTextorllm.chatoperations so you can bail out or queue work when units are low, rather than catching a usage-exceeded error mid-run. - Update your module imports. If you are already loading
N/llmyou do not need an additional dependency — the promise method hangs directly off the existinggetRemainingUsagefunction. - Distinguish paid vs. free balance. If your logic previously used
getRemainingFreeUsage, confirm whether you actually need the free-tier count or the total entitlement count. The two methods return different values.
Source: Oracle NetSuite Release Notes