Module: Amlexia::Anthropic

Defined in:
lib/amlexia/anthropic.rb

Class Method Summary collapse

Class Method Details

.track_anthropic_message(client, model:, status_code:, latency_ms:, usage: {}, cost_usd: nil, **kwargs) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/amlexia/anthropic.rb', line 7

def track_anthropic_message(client, model:, status_code:, latency_ms:, usage: {}, cost_usd: nil, **kwargs)
  event = Cost.enrich_event(
    cost_usd: cost_usd,
    model_name: model,
    provider: "anthropic",
    tokens_input: usage[:input_tokens],
    tokens_output: usage[:output_tokens]
  )
  client.track(
    endpoint: "/v1/messages",
    method: "POST",
    status_code: status_code,
    latency_ms: latency_ms,
    provider: "anthropic",
    model_name: model,
    tokens_input: usage[:input_tokens],
    tokens_output: usage[:output_tokens],
    cost_usd: event[:cost_usd],
    **kwargs
  )
end