Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

feature/cost-report-cli (#926)

Thomas Hebrard848b220fb161
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4af78a1f7..5163ffd3a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog
+## [Unreleased]
+
+### Fixed
+
+- **`pipelex run` now prints the aggregated cost table when `[pipelex.reporting_config].is_log_costs_to_console = true`, with `--cost-report/--no-cost-report` to override per invocation.** The `cost-tracking.md` and `reporting-config.md` docs both promised a summary cost table at the end of a CLI run, but `pipelex/cli/commands/run/_run_core.py` never called `get_report_delegate().generate_report()` — the flag only triggered `log.verbose(...)` lines per inference job, which the default `INFO` log level swallows, so the table never appeared. The CLI now calls `generate_report()` after a successful run when either `is_log_costs_to_console` or `is_generate_cost_report_file_enabled` is true, so the Rich table (one row per model, plus a totals row) prints right before the "✓ Pipeline execution completed successfully" recap — and the CSV export branch finally fires too. The new `--cost-report/--no-cost-report` tri-state flag (default unset → use config) lets you force the table on or off without touching `.pipelex/pipelex.toml`. Applies to `pipelex run bundle`, `pipelex run pipe`, and `pipelex run method`; works in dry-run mode as well (synthetic usage rows).
+
## [v0.29.0] - 2026-05-20
### Added
diff --git a/pipelex/cli/commands/run/_run_core.py b/pipelex/cli/commands/run/_run_core.py
index ea448a6c6..ca5db354e 100644
--- a/pipelex/cli/commands/run/_run_core.py
+++ b/pipelex/cli/commands/run/_run_core.py
@@ -22,7 +22,7 @@ from pipelex.core.interpreter.interpreter import PipelexInterpreter
from pipelex.core.pipes.exceptions import PipeOperatorModelChoiceError
from pipelex.core.stuffs.stuff_viewer import render_stuff_viewer
from pipelex.graph.graph_factory import generate_graph_outputs, save_graph_outputs_to_dir
-from pipelex.hub import get_console, get_telemetry_manager
+from pipelex.hub import get_console, get_report_delegate, get_telemetry_manager
from pipelex.pipe_operators.exceptions import PipeOperatorModelAvailabilityError
from pipelex.pipe_run.pipe_run_mode import PipeRunMode
from pipelex.pipelex import Pipelex
@@ -51,6 +51,7 @@ async def _execute_run(
dry_run: bool,
mock_inputs: bool,
library_dir: list[str] | None,
+ cost_report: bool | None,
dynamic_output_concept_ref: str | None = None,
) -> None:
"""Core async execution logic for running a pipe.
@@ -212,6 +213,14 @@ async def _execute_run(
save_as_json_to_path(object_to_save=working_memory_dict, path=working_memory_output_path)
log.verbose(f"Working memory saved to: {working_memory_output_path}")
+ reporting_config = get_config().pipelex.reporting_config
+ effective_cost_report = reporting_config.is_log_costs_to_console if cost_report is None else cost_report
+ if effective_cost_report or reporting_config.is_generate_cost_report_file_enabled:
+ try:
+ get_report_delegate().generate_report(pipeline_run_id=response.pipeline_run_id)
+ except OSError as cost_report_error:
+ log.warning(f"Cost report generation failed (run succeeded): {cost_report_error}")
+
# Print completion recap
console = get_console()
if dry_run:
@@ -245,6 +254,7 @@ def execute_run(
dry_run: bool,
mock_inputs: bool,
library_dir: list[str] | None,
+ cost_report: bool | None = None,
telemetry_command_label: str = COMMAND,
temporal: bool | None = None,
dynamic_output_concept_ref: str | None = None,
@@ -275,6 +285,7 @@ def execute_run(
dry_run=dry_run,
mock_inputs=mock_inputs,
library_dir=library_dir,
+ cost_report=cost_report,
dynamic_output_concept_ref=dynamic_output_concept_ref,
)
)
diff --git a/pipelex/cli/commands/run/bundle_cmd.py b/pipelex/cli/commands/run/bundle_cmd.py
index 745668069..b1d451f62 100644
--- a/pipelex/cli/commands/run/bundle_cmd.py
+++ b/pipelex/cli/commands/run/bundle_cmd.py
@@ -81,6 +81,13 @@ def run_bundle_cmd(
help="Concept ref (e.g. 'document_qa.ReferenceCount') used to resolve a pipe whose output is declared as 'Dynamic'.",
),
] = None,
+ cost_report: Annotated[
+ bool | None,
+ typer.Option(
+ "--cost-report/--no-cost-report",
+ help="Override config: enable or disable printing the aggregated inference cost table after the run",
+ ),
+ ] = None,
) -> None:
"""Run a pipeline from a bundle file (.mthds) or pipeline directory.
@@ -171,6 +178,7 @@ def run_bundle_cmd(
dry_run=dry_run,
mock_inputs=mock_inputs,
library_dir=library_dir,
+ cost_report=cost_report,
telemetry_command_label=f"{COMMAND} bundle",
temporal=temporal,
dynamic_output_concept_ref=dynamic_output_concept_ref,
diff --git a/pipelex/cli/commands/run/method_cmd.py b/pipelex/cli/commands/run/method_cmd.py
index 5e87e3f34..b0aefe4fc 100644
--- a/pipelex/cli/commands/run/method_cmd.py
+++ b/pipelex/cli/commands/run/method_cmd.py
@@ -80,6 +80,13 @@ def run_method_cmd(
help="Concept ref (e.g. 'document_qa.ReferenceCount') used to resolve a pipe whose output is declared as 'Dynamic'.",
),
] = None,
+ cost_report: Annotated[
+ bool | None,
+ typer.Option(
+ "--cost-report/--no-cost-report",
+ help="Override config: enable or disable printing the aggregated inference cost table after the run",
+ ),
+ ] = None,
) -> None:
"""Run an installed method by name.
@@ -141,6 +148,7 @@ def run_method_cmd(
dry_run=dry_run,
mock_inputs=mock_inputs,
library_dir=effective_library_dir,
+ cost_report=cost_report,
telemetry_command_label=f"{COMMAND} method",
temporal=temporal,
dynamic_output_concept_ref=dynamic_output_concept_ref,
diff --git a/pipelex/cli/commands/run/pipe_cmd.py b/pipelex/cli/commands/run/pipe_cmd.py
index c963a7372..58105363b 100644
--- a/pipelex/cli/commands/run/pipe_cmd.py
+++ b/pipelex/cli/commands/run/pipe_cmd.py
@@ -77,6 +77,13 @@ def run_pipe_cmd(
help="Concept ref (e.g. 'document_qa.ReferenceCount') used to resolve a pipe whose output is declared as 'Dynamic'.",
),
] = None,
+ cost_report: Annotated[
+ bool | None,
+ typer.Option(
+ "--cost-report/--no-cost-report",
+ help="Override config: enable or disable printing the aggregated inference cost table after the run",
+ ),
+ ] = None,
) -> None:
"""Run a pipe by code.
@@ -136,6 +143,7 @@ def run_pipe_cmd(
dry_run=dry_run,
mock_inputs=mock_inputs,
library_dir=library_dir,
+ cost_report=cost_report,
telemetry_command_label=f"{COMMAND} pipe",
temporal=temporal,
dynamic_output_concept_ref=dynamic_output_concept_ref,