LlmComposer.LlmResponse (llm_composer v0.19.3)

Copy Markdown View Source

Normalized representation of a response coming from any provider.

Parser modules are responsible for translating provider-specific HTTP results into this normalized struct so the rest of the library can stay provider-agnostic.

Summary

Types

t()

Normalized response from any LLM provider.

Functions

Returns the function calls from the main response message.

Builds an LlmResponse struct from an attribute map, defaulting :metadata to %{}.

Types

provider()

@type provider() ::
  :open_ai | :open_ai_responses | :ollama | :open_router | :bedrock | :google

t()

@type t() :: %LlmComposer.LlmResponse{
  cached_tokens: non_neg_integer() | nil,
  cost_info: LlmComposer.CostInfo.t() | nil,
  input_tokens: non_neg_integer() | nil,
  main_response: LlmComposer.Message.t() | nil,
  metadata: map(),
  output_tokens: non_neg_integer() | nil,
  previous_response: map() | nil,
  provider: provider(),
  provider_model: String.t() | nil,
  raw: any(),
  reasoning_tokens: non_neg_integer() | nil,
  response_id: String.t() | nil,
  status: :ok | :error,
  stream: nil | Enumerable.t()
}

Normalized response from any LLM provider.

  • :status:ok or :error.
  • :main_response — the primary assistant Message.t().
  • :input_tokens — number of input tokens consumed.
  • :output_tokens — number of output tokens generated.
  • :cached_tokens — number of tokens served from provider cache.
  • :reasoning_tokens — tokens used for internal reasoning (where supported).
  • :provider — atom identifying the provider (see provider/0 type).
  • :provider_model — model identifier string as reported by the provider.
  • :response_id — provider-assigned response ID, used for multi-turn continuations.
  • :previous_response — raw previous response map, used by stateful APIs (e.g. OpenAI Responses).
  • :stream — enumerable of LlmComposer.StreamChunk.t() when streaming is enabled, otherwise nil.
  • :cost_infoCostInfo.t() with cost breakdown when :track_costs is enabled.
  • :metadata — arbitrary map for provider-specific extra data.
  • :raw — original decoded provider payload, useful for debugging.

Functions

function_calls(llm_response)

@spec function_calls(t()) :: [LlmComposer.FunctionCall.t()] | nil

Returns the function calls from the main response message.

Delegates to main_response.function_calls for convenience.

new(attrs \\ %{})

@spec new(map()) :: t()

Builds an LlmResponse struct from an attribute map, defaulting :metadata to %{}.