Class LlmOptimisationReportBuilder

java.lang.Object
org.mockserver.llm.analysis.LlmOptimisationReportBuilder

public class LlmOptimisationReportBuilder extends Object
Builds a deterministic LlmOptimisationReport from captured LLM FORWARDED_REQUEST exchanges.

Pure and read-only: each exchange's request body is decoded with the provider's ProviderCodec, the provider is detected with LlmProviderSniffer, token usage is read from the response (via LlmClient.parseCompletionResponse(org.mockserver.model.HttpResponse)) or estimated from decoded text when the provider returned no usage, and cost is estimated with LlmPricing. No network and no LLM calls. The signal detectors (OptimisationSignals) run over the assembled calls.

Token estimation when usage is absent: a coarse ~4 chars per token heuristic over the decoded prompt/completion text; flagged with costIsEstimated = true so consumers know not to treat it as billed.

  • Constructor Details

    • LlmOptimisationReportBuilder

      public LlmOptimisationReportBuilder()
  • Method Details

    • build

      public LlmOptimisationReport build(List<LlmOptimisationReportBuilder.CapturedExchange> exchanges, String sessionKey, LlmOptimisationReport.GroupingBasis groupingBasis, List<String> redactedHeaders, List<String> redactedBodyFields)
      Build the report from the given exchanges. Non-LLM exchanges (no provider detected) are ignored. The report's session key/grouping is supplied by the caller (it has already grouped/filtered the traffic).
      Parameters:
      exchanges - captured forwarded request/response pairs, in chronological order
      sessionKey - the session/grouping key (e.g. host:api.openai.com)
      groupingBasis - how the traffic was grouped
      redactedHeaders - header names that were/are redacted before rendering
      redactedBodyFields - body field names that were/are redacted before rendering