Usage Object Members in SuiteScript for Token Management
Understand the Usage Object Members in SuiteScript for managing tokens in LLM requests and responses.
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
- Natural Language Queries in NetSuite AI
Updated for NetSuite 2026.1, featuring enhancements in natural language queries. The MCP Standard Tools SuiteApp offers enhanced AI-driven interaction with
- Support for Consolidated Reports and SuiteQL Tool
Updated to reflect the latest features added in NetSuite 2026.1. Starting with the latest updates in NetSuite 2026.1, NetSuite enhances reporting capabilities
- Intelligent Close Manager Portlet in NetSuite
The Intelligent Close Manager portlet offers a centralized view for managing tasks and exceptions in NetSuite, enhancing close processes.
- New SuiteCloud Agent Skills for NetSuite 2026.1
NetSuite 2026.1 introduces new SuiteCloud Agent Skills, enhancing security and development workflows.
Advertising
Reach AI Professionals
Put your product in front of NetSuite experts who work with AI every day.
Sponsor This Category