N/llm Module Adds getRemainingUsage() to Check AI Unit Balance
The N/llm module now exposes llm.getRemainingUsage(), a zero-governance method that returns the number of AI Units still available in the account. Server-side scripts can use it to guard against exhaustion before making LLM calls.
What changed
A new top-level method, llm.getRemainingUsage(), has been added to the N/llm module starting in 2026.1. It returns a number representing the AI Units still available to the account.
- Module:
N/llm - Method:
llm.getRemainingUsage() - Return type:
number - Governance: None
- Script types: Server-side scripts only (Scheduled, Map/Reduce, Suitelet, User Event, RESTlet, etc.)
Because the call itself carries zero governance, you can invoke it liberally — for example, at the top of a Map/Reduce stage or before each prompt — without worrying about unit consumption from the check itself.
AI Units are the metered resource that gates calls to NetSuite's LLM features. Oracle documents the allocation model in the NetSuite AI Units and NetSuite Features and AI Units FAQ help topics. The exact per-call cost of other N/llm methods (such as llm.generateText()) is documented separately; getRemainingUsage() simply tells you how many units you have left before those calls start failing.
Example
/**
* @NApiVersion 2.1
* @NScriptType ScheduledScript
*/
define(['N/llm', 'N/log'], (llm, log) => {
const execute = (context) => {
const remaining = llm.getRemainingUsage();
log.audit({ title: 'AI Units remaining', details: remaining });
if (remaining < 100) {
log.error({ title: 'Low AI Units', details: 'Skipping LLM call.' });
return;
}
// Proceed with llm.generateText() or other N/llm calls
};
return { execute };
});What to do
- Add guard clauses. If your scripts already call
N/llmmethods likellm.generateText(), wrap them with agetRemainingUsage()check so they degrade gracefully when the account is running low on AI Units rather than throwing an unexpected error. - Instrument monitoring. Consider logging the return value in scheduled or Map/Reduce scripts that make heavy LLM use. This gives you an audit trail of consumption patterns you can review in the Script Execution Log or forward to an external observability stack.
- Set a threshold, not just zero. Individual LLM calls consume a variable number of AI Units depending on the operation. Check against a buffer (e.g.,
remaining < 100) rather than=== 0to avoid race conditions in high-concurrency scenarios. - Review AI Unit allocation. If you haven't already, read the NetSuite AI Units help topic to understand how units are provisioned and replenished for your account tier.
Source: Oracle NetSuite Release Notes