View Source LlmComposer.Cost.CostAssembler (llm_composer v0.13.0)

Centralized cost information assembly module.

Handles the extraction of cost-related data from provider responses and assembles CostInfo structs. This module consolidates all cost logic that was previously scattered across the response handler.

Responsibilities

  • Extract tokens from provider-specific response formats
  • Resolve model names (from response or options)
  • Prepare pricing options for cost calculation
  • Assemble complete CostInfo structs

Provider-Specific Handling

  • OpenAI/OpenRouter: Extracts tokens from usage field, model from response
  • Google: Extracts tokens from usageMetadata field, model from options

Summary

Functions

Link to this function

extract_tokens(provider, raw_response)

View Source
@spec extract_tokens(atom(), map()) :: {non_neg_integer(), non_neg_integer()}
Link to this function

get_cost_info(provider, raw_response, opts)

View Source
@spec get_cost_info(
  provider :: atom(),
  raw_response :: map(),
  opts :: keyword()
) :: LlmComposer.CostInfo.t() | nil