Module: LlmCostTracker::Integrations::Openai::ResponsesPatch

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

Instance Method Summary collapse

Instance Method Details

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



359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/llm_cost_tracker/integrations/openai.rb', line 359

def create(*args, **kwargs)
  request = LlmCostTracker::Integrations::Openai.request_params(args, kwargs)
  LlmCostTracker::Integrations::Openai.enforce_budget!(request: request)
  started_at = LlmCostTracker::Timing.now_monotonic
  response = super(*LlmCostTracker::Integrations::Openai.normalize_sdk_args(args, kwargs))
  LlmCostTracker::Integrations::Openai.record_response(
    response,
    request: request,
    latency_ms: LlmCostTracker::Timing.elapsed_ms(started_at),
    host: LlmCostTracker::Integrations::Openai.client_host_for(self)
  )
  response
end

#retrieve_streaming(response_id, *args, **kwargs) ⇒ Object



385
386
387
388
389
390
# File 'lib/llm_cost_tracker/integrations/openai.rb', line 385

def retrieve_streaming(response_id, *args, **kwargs)
  LlmCostTracker::Integrations::Openai.wrap_stream_call(args, kwargs, self) do |normalized, collector|
    collector.provider_response_id = response_id
    super(response_id, *normalized)
  end
end

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



373
374
375
376
377
# File 'lib/llm_cost_tracker/integrations/openai.rb', line 373

def stream(*args, **kwargs)
  LlmCostTracker::Integrations::Openai.wrap_stream_call(args, kwargs, self) do |normalized, _|
    super(*normalized)
  end
end

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



379
380
381
382
383
# File 'lib/llm_cost_tracker/integrations/openai.rb', line 379

def stream_raw(*args, **kwargs)
  LlmCostTracker::Integrations::Openai.wrap_stream_call(args, kwargs, self) do |normalized, _|
    super(*normalized)
  end
end