Module: LlmCostTracker::Integrations::Anthropic::MessagesPatch

Defined in:
lib/llm_cost_tracker/integrations/anthropic.rb

Instance Method Summary collapse

Instance Method Details

#create(*args, **kwargs) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
# File 'lib/llm_cost_tracker/integrations/anthropic.rb', line 135

def create(*args, **kwargs)
  LlmCostTracker::Integrations::Anthropic.enforce_budget!
  started_at = LlmCostTracker::Timing.now_monotonic
  message = super
  LlmCostTracker::Integrations::Anthropic.record_message(
    message,
    request: LlmCostTracker::Integrations::Anthropic.request_params(args, kwargs),
    latency_ms: LlmCostTracker::Integrations::Anthropic.elapsed_ms(started_at)
  )
  message
end

#stream(*args, **kwargs) ⇒ Object



147
148
149
150
151
152
153
# File 'lib/llm_cost_tracker/integrations/anthropic.rb', line 147

def stream(*args, **kwargs)
  request = LlmCostTracker::Integrations::Anthropic.request_params(args, kwargs)
  LlmCostTracker::Integrations::Anthropic.enforce_budget!
  collector = LlmCostTracker::Integrations::Anthropic.stream_collector(request)
  stream = super
  LlmCostTracker::Integrations::Anthropic.track_stream(stream, collector: collector)
end

#stream_raw(*args, **kwargs) ⇒ Object



155
156
157
158
159
160
161
# File 'lib/llm_cost_tracker/integrations/anthropic.rb', line 155

def stream_raw(*args, **kwargs)
  request = LlmCostTracker::Integrations::Anthropic.request_params(args, kwargs)
  LlmCostTracker::Integrations::Anthropic.enforce_budget!
  collector = LlmCostTracker::Integrations::Anthropic.stream_collector(request)
  stream = super
  LlmCostTracker::Integrations::Anthropic.track_stream(stream, collector: collector)
end