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



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

def completion_tokens
  @completion_tokens
end

#cost_usdObject

Returns the value of attribute cost_usd

Returns:

  • (Object)

    the current value of cost_usd



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

def cost_usd
  @cost_usd
end

#prompt_tokensObject

Returns the value of attribute prompt_tokens

Returns:

  • (Object)

    the current value of prompt_tokens



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

def prompt_tokens
  @prompt_tokens
end

#total_tokensObject

Returns the value of attribute total_tokens

Returns:

  • (Object)

    the current value of total_tokens



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

def total_tokens
  @total_tokens
end

Instance Method Details

#+(other) ⇒ Object



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

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



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

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