Calling AI APIs from SuiteScript in 2026 — Patterns, Governance, and Production Use Cases
- SuiteScript 2.1 can call any external REST API via the N/https module — including Anthropic, OpenAI, and Google Gemini APIs for AI-powered automation inside NetSuite.
- The five production patterns in use in 2026: vendor bill classification, PO approval summarisation, customer risk scoring, GL account suggestion, and email draft generation.
- Governance is the hard constraint: each https.post() costs governance units. Scheduled Scripts and Map/Reduce are the only script types with enough budget for high-volume AI calls.
- API key security: always use Script Deployment Parameters for credentials — never hardcode. Rotate keys quarterly and track per-deployment usage via the AI provider’s dashboard.
NetSuite has no native AI. But SuiteScript 2.1’s N/https module can call any external REST API — which means you can call Anthropic, OpenAI, or any AI provider directly from a SuiteScript, passing NetSuite data as context and writing AI-generated output back to NetSuite records. This unlocks a class of automation that was not possible inside ERP environments two years ago.
The Five Production Patterns
A Scheduled Script reads unclassified vendor bills from the last 24 hours and calls an LLM to suggest the correct GL account, cost centre, and approval routing. Output is written to custom fields on the bill record for human review before final posting.
A Workflow Action fires when a PO enters “Pending Approval”. It calls the LLM with PO lines, vendor history, and budget data, and writes a one-paragraph decision summary to a custom field. The approver sees the summary in their approval notification.
A weekly Scheduled Script computes a risk score for each Customer by sending payment history, days-past-due averages, and order frequency to an LLM. Scores are written to a custom customer field and drive credit limit review alerts.
A User Event fires on Expense Report submission. For each expense line without a GL account, the LLM receives the merchant name, amount, and expense category and suggests the most likely account. High-confidence suggestions are auto-applied; others route to the submitter for confirmation.
A Scheduled Script runs daily, identifies customers with invoices past due, and calls the LLM to draft a tone-appropriate collection email for each. Emails are staged for review in a custom record before a manager sends them — not auto-sent.
The SuiteScript Pattern
define(['N/https', 'N/runtime'], function(https, runtime) {
function callClaude(prompt) {
var apiKey = runtime.getCurrentScript()
.getParameter('custscript_anthropic_key');
var response = https.post({
url: 'https://api.anthropic.com/v1/messages',
headers: {
'Content-Type': 'application/json',
'x-api-key': apiKey,
'anthropic-version': '2023-06-01'
},
body: JSON.stringify({
model: 'claude-sonnet-4-6',
max_tokens: 512,
messages: [{ role: 'user', content: prompt }]
})
});
var result = JSON.parse(response.body);
return result.content[0].text;
}
return { callClaude: callClaude };
});
User Event scripts have 1,000 governance units. A single https.post() to an AI API costs approximately 200 units. This leaves room for 4–5 AI calls per User Event execution — enough for 1 call per record with buffer. For bulk processing (100+ records), use Scheduled Script (10,000 units) or Map/Reduce (10,000 units per key) to avoid governance limit errors.
References
- SuiteScript N/https ModuleOracle NetSuite Help — https.post() reference for calling external REST APIs from SuiteScript.
- Anthropic Claude Messages APIAnthropic — the API endpoint called in the SuiteScript pattern above, with model IDs and request format.
- SuiteScript Governance ReferenceOracle NetSuite Help — governance units per API module call, critical for planning AI call budgets.
Leave a Reply