Class: Parse::Agent::MCPClient::Usage

Inherits:
Struct
  • Object
show all
Defined in:
lib/parse/agent/mcp_client.rb

Overview

Token + cost roll-up. cost_usd is computed from the model's pricing row; values are USD dollars (NOT cents). Returned per-call and as a running total via client.usage.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#completion_tokensObject

Returns the value of attribute completion_tokens

Returns:

  • (Object)

    the current value of completion_tokens



115
116
117
# File 'lib/parse/agent/mcp_client.rb', line 115

def completion_tokens
  @completion_tokens
end

#cost_usdObject

Returns the value of attribute cost_usd

Returns:

  • (Object)

    the current value of cost_usd



115
116
117
# File 'lib/parse/agent/mcp_client.rb', line 115

def cost_usd
  @cost_usd
end

#prompt_tokensObject

Returns the value of attribute prompt_tokens

Returns:

  • (Object)

    the current value of prompt_tokens



115
116
117
# File 'lib/parse/agent/mcp_client.rb', line 115

def prompt_tokens
  @prompt_tokens
end

#total_tokensObject

Returns the value of attribute total_tokens

Returns:

  • (Object)

    the current value of total_tokens



115
116
117
# File 'lib/parse/agent/mcp_client.rb', line 115

def total_tokens
  @total_tokens
end

Instance Method Details

#+(other) ⇒ Object



116
117
118
119
120
121
122
123
# File 'lib/parse/agent/mcp_client.rb', line 116

def +(other)
  Usage.new(
    prompt_tokens: prompt_tokens + other.prompt_tokens,
    completion_tokens: completion_tokens + other.completion_tokens,
    total_tokens: total_tokens + other.total_tokens,
    cost_usd: cost_usd + other.cost_usd,
  )
end

#to_sObject Also known as: inspect



125
126
127
128
# File 'lib/parse/agent/mcp_client.rb', line 125

def to_s
  format("%d in + %d out = %d tokens   $%.6f",
         prompt_tokens, completion_tokens, total_tokens, cost_usd)
end