AS AgentScopeAPI 手册 / API Reference

ChatUsage

public class ChatUsage
源码Source io/agentscope/core/model/ChatUsage.java:28–311

聊天用量,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.core.model 包。核心成员包括 getInputTokens、getOutputTokens、getCachedTokens、getCacheCreationTokens、getReasoningTokens、getToolUsePromptTokens。

Represents token usage information for chat completion responses.

This immutable data class tracks the number of tokens used during a chat completion, including input tokens (prompt), output tokens (generated response), input/output token breakdowns, and execution time.

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
构建器,用于构建并配置目标实例。
Builder for creating ChatUsage instances.

构造器摘要Constructor Summary

构造器Constructor说明Description
public ChatUsage(int inputTokens, int outputTokens, double time)
初始化 `ChatUsage` 实例。
Creates a new ChatUsage instance without token breakdowns.
public ChatUsage(int inputTokens, int outputTokens, int cachedTokens, double time)
创建新的ChatUsage 实例。
Creates a new ChatUsage instance.
public ChatUsage(int inputTokens, int outputTokens, int cachedTokens, int cacheCreationTokens, int reasoningTokens, int toolUsePromptTokens, double time)
初始化 `ChatUsage` 实例。
Creates a new ChatUsage instance with all token breakdowns.

方法摘要Method Summary

方法Method说明Description
public int getInputTokens()
获取输入令牌数。
Gets the number of input tokens used.
public int getOutputTokens()
获取输出令牌数。
Gets the number of output tokens used.
public int getCachedTokens()
获取已缓存令牌数。
Gets the number of input tokens served from the prompt cache.
public int getCacheCreationTokens()
获取 `getCacheCreationTokens`。
Gets the number of input tokens used to create a prompt cache entry.
public int getReasoningTokens()
获取推理令牌数。
Gets the number of output tokens used for model reasoning.
public int getToolUsePromptTokens()
获取工具使用提示词令牌数。
Gets the number of input tokens representing tool results returned to the model.
public int getTotalTokens()
获取总数令牌数。
Gets the total number of tokens used.
public double getTime()
获取执行时间。
Gets the execution time.
public static Builder builder()
static
创建新的构建器用于 ChatUsage。
Creates a new builder for ChatUsage.

构造器详情Constructor Detail

ChatUsage

public ChatUsage(int inputTokens, int outputTokens, double time)

初始化 ChatUsage 实例。

Creates a new ChatUsage instance without token breakdowns.

参数Parameters
名称Name类型Type说明Description
inputTokensint输入令牌数(类型 `int`)。the number of tokens used for the input/prompt
outputTokensint输出令牌数(类型 `int`)。the number of tokens used for the output/generated response
timedouble执行时间 in 秒。the execution time in seconds
源码Source io/agentscope/core/model/ChatUsage.java:48–50

ChatUsage

public ChatUsage(int inputTokens, int outputTokens, int cachedTokens, double time)

创建新的ChatUsage 实例。

Creates a new ChatUsage instance.

参数Parameters
名称Name类型Type说明Description
inputTokensint输入令牌数(类型 `int`)。the number of tokens used for the input/prompt
outputTokensint输出令牌数(类型 `int`)。the number of tokens used for the output/generated response
cachedTokensint已缓存令牌数(类型 `int`)。the number of input tokens served from the prompt cache (a subset of `inputTokens`); `0` when the provider does not report cache information
timedouble执行时间 in 秒。the execution time in seconds
源码Source io/agentscope/core/model/ChatUsage.java:61–67

ChatUsage

public ChatUsage(int inputTokens, int outputTokens, int cachedTokens, int cacheCreationTokens, int reasoningTokens, int toolUsePromptTokens, double time)

初始化 ChatUsage 实例。

Creates a new ChatUsage instance with all token breakdowns.

参数Parameters
名称Name类型Type说明Description
inputTokensint输入令牌数(类型 `int`)。the number of tokens used for the input/prompt
outputTokensint输出令牌数(类型 `int`)。the number of tokens used for the output/generated response
cachedTokensint已缓存令牌数(类型 `int`)。the number of input tokens served from the prompt cache (a subset of `inputTokens`); `0` when the provider does not report cache information
cacheCreationTokensint缓存 Creation 令牌数(类型 `int`)。the number of input tokens used to create a prompt cache entry (a subset of `inputTokens`); `0` when the provider does not report this information
reasoningTokensint推理令牌数(类型 `int`)。the number of output tokens used for model reasoning (a subset of `outputTokens`); `0` when the provider does not report this information
toolUsePromptTokensint工具使用提示词令牌数(类型 `int`)。the number of input tokens representing tool results returned to the model (a subset of `inputTokens`); `0` when the provider does not report this information
timedouble执行时间 in 秒。the execution time in seconds
源码Source io/agentscope/core/model/ChatUsage.java:89–105

方法详情Method Detail

getInputTokens

public int getInputTokens()

获取输入令牌数。

Gets the number of input tokens used.

返回Returns int
返回数值结果。the number of tokens used for the input/prompt
源码Source io/agentscope/core/model/ChatUsage.java:112–114

getOutputTokens

public int getOutputTokens()

获取输出令牌数。

Gets the number of output tokens used.

返回Returns int
返回数值结果。the number of tokens used for the output/generated response
源码Source io/agentscope/core/model/ChatUsage.java:121–123

getCachedTokens

public int getCachedTokens()

获取已缓存令牌数。

Gets the number of input tokens served from the prompt cache.

返回Returns int
已缓存输入令牌数的数量。the number of cached input tokens
源码Source io/agentscope/core/model/ChatUsage.java:134–136

getCacheCreationTokens

public int getCacheCreationTokens()

获取 getCacheCreationTokens。

Gets the number of input tokens used to create a prompt cache entry.

返回Returns int
返回数值结果。the number of cache-creation input tokens
源码Source io/agentscope/core/model/ChatUsage.java:147–149

getReasoningTokens

public int getReasoningTokens()

获取推理令牌数。

Gets the number of output tokens used for model reasoning.

返回Returns int
推理输出令牌数的数量。the number of reasoning output tokens
源码Source io/agentscope/core/model/ChatUsage.java:159–161

getToolUsePromptTokens

public int getToolUsePromptTokens()

获取工具使用提示词令牌数。

Gets the number of input tokens representing tool results returned to the model.

返回Returns int
返回数值结果。the number of tool-result input tokens
源码Source io/agentscope/core/model/ChatUsage.java:171–173

getTotalTokens

public int getTotalTokens()

获取总数令牌数。

Gets the total number of tokens used.

返回Returns int
返回数值结果。the sum of input and output tokens
源码Source io/agentscope/core/model/ChatUsage.java:180–182

getTime

public double getTime()

获取执行时间。

Gets the execution time.

返回Returns double
执行时间 in 秒。the execution time in seconds
源码Source io/agentscope/core/model/ChatUsage.java:189–191

builder

public static Builder builder()
static

创建新的构建器用于 ChatUsage。

Creates a new builder for ChatUsage.

返回Returns Builder
一种新的构建器实例。a new Builder instance
源码Source io/agentscope/core/model/ChatUsage.java:198–200

嵌套类详情Nested Class Detail

Builder

public static class Builder

构建器,用于构建并配置目标实例。位于 io.agentscope.core.model 包。核心成员包括 inputTokens、outputTokens、cachedTokens、cacheCreationTokens、reasoningTokens、toolUsePromptTokens。

Builder for creating ChatUsage instances.

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.