Usage Object Members in SuiteScript for Token Management
Explore Usage Object Members in SuiteScript to effectively track token management during LLM interactions.
The Usage Object Members in SuiteScript provide essential metrics for tracking the token usage when interacting with large language models (LLMs). This includes properties that monitor requests and responses, which is crucial for optimizing API usage and managing costs effectively.
What Are Usage Object Members?
The Usage Object contains properties that give developers insight into how many tokens are being processed during interactions with LLMs. These members specifically cater to server scripts and track tokens as follows:
| Member Name | Return Type | Description |
|---|---|---|
Usage.completionTokens | number | Number of tokens in the response from the LLM. |
Usage.promptTokens | number | Number of tokens in the request sent to the LLM. |
Usage.totalTokens | number | Total number of tokens for the entire LLM interaction. |
Property Descriptions
Usage.completionTokens: This property returns the number of tokens in the LLM's response, allowing for efficiency assessments in output generation.Usage.promptTokens: It indicates the number of tokens included in the prompt sent to the LLM, necessary for understanding request sizes and potential costs.Usage.totalTokens: Represents the total tokens utilized in the request/response cycle, which is essential for overall resource management.
Error Codes
When working with these members, you may encounter specific error codes:
READ_ONLY: This error occurs if there is an attempt to set the value of a property that is read-only.
Example Usage in Scripts
Here's a sample code snippet demonstrating how to access the token properties within a SuiteScript:
1// Sample SuiteScript demonstrating usage object members2const response = llm.generateText({3 prompt: "Write a 200 word pitch for a TV show about elephants."4});5 6const usageCompletionTokens = response.usage.completionTokens; 7const usagePromptTokens = response.usage.promptTokens; 8const totalTokens = response.usage.totalTokens;This snippet showcases the retrieval of token-related data after generating text through the LLM, which can be invaluable for monitoring and optimizing your LLM utilization.
Who This Affects
- Administrators: Those managing API quotas and monitoring system resources.
- Developers: Individuals implementing LLM features using SuiteScript.
Key Takeaways
- The Usage Object Members help track token usage efficiently during LLM interactions.
- Crucial for developers to manage request costs and optimize performance.
- Understanding token metrics can enhance API management and application responsiveness.
Frequently Asked Questions (4)
How can SuiteScript developers use the Usage Object Members to optimize API usage?
What should developers be aware of when working with Usage Object Member properties in SuiteScript?
Do Usage Object Members apply to all types of NetSuite scripts?
What kind of information can be gathered from `Usage.totalTokens` in the Usage Object?
Was this article helpful?
More in AI
- Prompt Studio: Generative AI Management in NetSuite 2026.1
Prompt Studio in NetSuite 2026.1 enhances generative AI management, enabling customization of prompts and Text Enhance actions.
- SuiteCloud Agent Skills for AI Development in NetSuite 2026.1
SuiteCloud Agent Skills enhance development workflows with AI-driven guidance in NetSuite 2026.1, improving automation and process standardization.
- N/llm Module: Usage Limits and Additional Requests in NetSuite
In NetSuite 2026.1, the N/llm module sets usage limits and options for additional requests via Oracle Cloud.
- Required Features and Permissions for NetSuite AI Connector
Ensure Server SuiteScript and OAuth 2.0 are enabled for secure usage of the NetSuite AI Connector Service.
Advertising
Reach AI Professionals
Put your product in front of NetSuite experts who work with AI every day.
Sponsor This Category