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.
Docs/starter js (#928)
Louis Choquel593584ea7139
diff --git a/.pipelex/plxt.toml b/.pipelex/plxt.tomlindex a58912708..df34dafcd 100644--- a/.pipelex/plxt.toml+++ b/.pipelex/plxt.toml@@ -1,5 +1,5 @@# =============================================================================-# Pipelex TOML Configuration for pipelex-demo+# PLXT Configuration# =============================================================================# Configures MTHDS/TOML formatting and linting behaviour for this project.# Powered by the Pipelex extension (plxt / taplo engine).diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5163ffd3a..bb0905987 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,7 +4,7 @@### 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).+- **`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 cost table on for a single invocation (`--cost-report`) or skip reporting entirely — no Rich table **and** no CSV file (`--no-cost-report`) — 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-20diff --git a/README.md b/README.mdindex 94ef4d5ec..f6f487a41 100644--- a/README.md+++ b/README.md@@ -461,10 +461,21 @@ The same `.mthds` file runs from multiple execution targets:|--------|-----|| **CLI** | `pipelex run bundle method.mthds --inputs inputs.json` || **Python** | `PipelexRunner().execute_pipeline(...)` |+| **TypeScript / Node** | [`mthds`](https://www.npmjs.com/package/mthds) SDK calling a Pipelex API server || **REST API** | Self-hosted API server || **MCP** | Model Context Protocol — agents call methods as tools || **n8n** | Pipelex node for workflow automation |+## Use Pipelex from TypeScript++For Node, Next.js, or any TypeScript app, call a Pipelex API server via the [`mthds`](https://www.npmjs.com/package/mthds) npm SDK (source: [`mthds-js`](https://github.com/mthds-ai/mthds-js)). Self-host the open-source [`pipelex-api`](https://github.com/Pipelex/pipelex-api) and point the SDK at your instance. A Pipelex-hosted runner at `api.pipelex.com` is also available in private beta — [join the waitlist](https://go.pipelex.com/waitlist).++```bash+npm install mthds+```++Fastest way to get started: fork the [`pipelex-starter-js`](https://github.com/Pipelex/pipelex-starter-js) template — a Next.js 16 + TypeScript app with three working demos (text entity extraction, PDF summary, image generation). Click *Use this template* on GitHub.+# The MTHDS Ecosystemdiff --git a/pipelex/cli/commands/run/_run_core.py b/pipelex/cli/commands/run/_run_core.pyindex ca5db354e..60a48cc92 100644--- a/pipelex/cli/commands/run/_run_core.py+++ b/pipelex/cli/commands/run/_run_core.py@@ -214,12 +214,18 @@ async def _execute_run(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}")+ # --no-cost-report (cost_report is False) skips the report entirely: no table, no CSV.+ # Otherwise: console follows the flag (if given) or config; CSV follows config.+ if cost_report is not False:+ print_to_console = cost_report or reporting_config.is_log_costs_to_console+ if print_to_console or reporting_config.is_generate_cost_report_file_enabled:+ try:+ get_report_delegate().generate_report(+ pipeline_run_id=response.pipeline_run_id,+ print_to_console=print_to_console,+ )+ except (OSError, PipelexError) as cost_report_error:+ log.warning(f"Cost report generation failed (run succeeded): {cost_report_error}")# Print completion recapconsole = get_console()diff --git a/pipelex/cli/commands/run/bundle_cmd.py b/pipelex/cli/commands/run/bundle_cmd.pyindex b1d451f62..280c1d176 100644--- a/pipelex/cli/commands/run/bundle_cmd.py+++ b/pipelex/cli/commands/run/bundle_cmd.py@@ -85,7 +85,7 @@ def run_bundle_cmd(bool | None,typer.Option("--cost-report/--no-cost-report",- help="Override config: enable or disable printing the aggregated inference cost table after the run",+ help="Override config: --cost-report forces the cost table on; --no-cost-report skips reporting entirely (no table and no CSV file).",),] = None,) -> None:diff --git a/pipelex/cli/commands/run/method_cmd.py b/pipelex/cli/commands/run/method_cmd.pyindex b0aefe4fc..17cf0e662 100644--- a/pipelex/cli/commands/run/method_cmd.py+++ b/pipelex/cli/commands/run/method_cmd.py@@ -84,7 +84,7 @@ def run_method_cmd(bool | None,typer.Option("--cost-report/--no-cost-report",- help="Override config: enable or disable printing the aggregated inference cost table after the run",+ help="Override config: --cost-report forces the cost table on; --no-cost-report skips reporting entirely (no table and no CSV file).",),] = None,) -> None:diff --git a/pipelex/cli/commands/run/pipe_cmd.py b/pipelex/cli/commands/run/pipe_cmd.pyindex 58105363b..055c390c7 100644--- a/pipelex/cli/commands/run/pipe_cmd.py+++ b/pipelex/cli/commands/run/pipe_cmd.py@@ -81,7 +81,7 @@ def run_pipe_cmd(bool | None,typer.Option("--cost-report/--no-cost-report",- help="Override config: enable or disable printing the aggregated inference cost table after the run",+ help="Override config: --cost-report forces the cost table on; --no-cost-report skips reporting entirely (no table and no CSV file).",),] = None,) -> None:diff --git a/pipelex/cogt/usage/cost_registry.py b/pipelex/cogt/usage/cost_registry.pyindex a427c1ec1..a731c6205 100644--- a/pipelex/cogt/usage/cost_registry.py+++ b/pipelex/cogt/usage/cost_registry.py@@ -42,6 +42,7 @@ class CostRegistry(RootModel[CostRegistryRoot]):tokens_usages: Sequence[TokensUsage],unit_scale: float,cost_report_file_path: Path | None = None,+ print_to_console: bool = True,):if not tokens_usages:if pipeline_run_id != "untitled":@@ -115,69 +116,70 @@ class CostRegistry(RootModel[CostRegistryRoot]):msg = "Empty report aggregation by model name"raise CostRegistryError(msg)- console = get_console()- title = f"Costs by model for pipeline '{pipeline_run_id}'"- table = Table(title=title, box=box.ROUNDED)+ if print_to_console:+ console = get_console()+ title = f"Costs by model for pipeline '{pipeline_run_id}'"+ table = Table(title=title, box=box.ROUNDED)- scale_str: str- if unit_scale == 1:- scale_str = ""- else:- scale_str = str(unit_scale)- # Add columns- table.add_column("Model", style="cyan", overflow="fold", width=30)- table.add_column("Type", style="dim cyan", width=8)- table.add_column("Input Cached", justify="right", style="green")- table.add_column("Input Non Cached", justify="right", style="green")- table.add_column("Input Joined", justify="right", style="green")- table.add_column("Output", justify="right", style="green")- table.add_column(f"Input Cached Cost ({scale_str}$)", justify="right", style="yellow")- table.add_column(f"Input Non Cached Cost ({scale_str}$)", justify="right", style="yellow")- table.add_column(f"Input Joined Cost ({scale_str}$)", justify="right", style="yellow")- table.add_column(f"Output Cost ({scale_str}$)", justify="right", style="yellow")- table.add_column(f"Total Cost ({scale_str}$)", justify="right", style="bold yellow")+ scale_str: str+ if unit_scale == 1:+ scale_str = ""+ else:+ scale_str = str(unit_scale)+ # Add columns+ table.add_column("Model", style="cyan", overflow="fold", width=30)+ table.add_column("Type", style="dim cyan", width=8)+ table.add_column("Input Cached", justify="right", style="green")+ table.add_column("Input Non Cached", justify="right", style="green")+ table.add_column("Input Joined", justify="right", style="green")+ table.add_column("Output", justify="right", style="green")+ table.add_column(f"Input Cached Cost ({scale_str}$)", justify="right", style="yellow")+ table.add_column(f"Input Non Cached Cost ({scale_str}$)", justify="right", style="yellow")+ table.add_column(f"Input Joined Cost ({scale_str}$)", justify="right", style="yellow")+ table.add_column(f"Output Cost ({scale_str}$)", justify="right", style="yellow")+ table.add_column(f"Total Cost ({scale_str}$)", justify="right", style="bold yellow")- # Add rows for each model- for model_name, aggregated_data in grouped_by_model.items():- row_total_cost = cls.compute_total_cost(- input_non_cached_cost=aggregated_data[report_field.COST_INPUT_NON_CACHED],- input_cached_cost=aggregated_data[report_field.COST_INPUT_CACHED],- output_cost=aggregated_data[report_field.COST_OUTPUT],- )+ # Add rows for each model+ for model_name, aggregated_data in grouped_by_model.items():+ row_total_cost = cls.compute_total_cost(+ input_non_cached_cost=aggregated_data[report_field.COST_INPUT_NON_CACHED],+ input_cached_cost=aggregated_data[report_field.COST_INPUT_CACHED],+ output_cost=aggregated_data[report_field.COST_OUTPUT],+ )+ table.add_row(+ model_name,+ model_types.get(model_name, "llm"),+ f"{int(aggregated_data[report_field.NB_TOKENS_INPUT_CACHED]):,}",+ f"{int(aggregated_data[report_field.NB_TOKENS_INPUT_NON_CACHED]):,}",+ f"{int(aggregated_data[report_field.NB_TOKENS_INPUT_JOINED]):,}",+ f"{int(aggregated_data[report_field.NB_TOKENS_OUTPUT]):,}",+ f"{aggregated_data[report_field.COST_INPUT_CACHED] / unit_scale:.4f}",+ f"{aggregated_data[report_field.COST_INPUT_NON_CACHED] / unit_scale:.4f}",+ f"{aggregated_data[report_field.COST_INPUT_JOINED] / unit_scale:.4f}",+ f"{aggregated_data[report_field.COST_OUTPUT] / unit_scale:.4f}",+ f"{row_total_cost / unit_scale:.4f}",+ )++ # add total row+ footer_style = "bold"table.add_row(- model_name,- model_types.get(model_name, "llm"),- f"{int(aggregated_data[report_field.NB_TOKENS_INPUT_CACHED]):,}",- f"{int(aggregated_data[report_field.NB_TOKENS_INPUT_NON_CACHED]):,}",- f"{int(aggregated_data[report_field.NB_TOKENS_INPUT_JOINED]):,}",- f"{int(aggregated_data[report_field.NB_TOKENS_OUTPUT]):,}",- f"{aggregated_data[report_field.COST_INPUT_CACHED] / unit_scale:.4f}",- f"{aggregated_data[report_field.COST_INPUT_NON_CACHED] / unit_scale:.4f}",- f"{aggregated_data[report_field.COST_INPUT_JOINED] / unit_scale:.4f}",- f"{aggregated_data[report_field.COST_OUTPUT] / unit_scale:.4f}",- f"{row_total_cost / unit_scale:.4f}",+ "Total",+ "",+ f"{total_nb_tokens_input_cached:,}",+ f"{total_nb_tokens_input_non_cached:,}",+ f"{total_nb_tokens_input_joined:,}",+ f"{total_nb_tokens_output:,}",+ f"{total_cost_input_cached / unit_scale:.4f}",+ f"{total_cost_input_non_cached / unit_scale:.4f}",+ f"{total_cost_input_joined / unit_scale:.4f}",+ f"{total_cost_output / unit_scale:.4f}",+ f"{total_cost / unit_scale:.4f}",+ style=footer_style,+ end_section=True,)- # add total row- footer_style = "bold"- table.add_row(- "Total",- "",- f"{total_nb_tokens_input_cached:,}",- f"{total_nb_tokens_input_non_cached:,}",- f"{total_nb_tokens_input_joined:,}",- f"{total_nb_tokens_output:,}",- f"{total_cost_input_cached / unit_scale:.4f}",- f"{total_cost_input_non_cached / unit_scale:.4f}",- f"{total_cost_input_joined / unit_scale:.4f}",- f"{total_cost_output / unit_scale:.4f}",- f"{total_cost / unit_scale:.4f}",- style=footer_style,- end_section=True,- )-- console.print(table)- console.print(" [dim]Note: some costs might be missing or not up-to-date.[/dim]")+ console.print(table)+ console.print(" [dim]Note: some costs might be missing or not up-to-date.[/dim]")if cost_report_file_path:cls.save_to_csv(records, cost_report_file_path)diff --git a/pipelex/kit/configs/plxt.toml b/pipelex/kit/configs/plxt.tomlindex a58912708..df34dafcd 100644--- a/pipelex/kit/configs/plxt.toml+++ b/pipelex/kit/configs/plxt.toml@@ -1,5 +1,5 @@# =============================================================================-# Pipelex TOML Configuration for pipelex-demo+# PLXT Configuration# =============================================================================# Configures MTHDS/TOML formatting and linting behaviour for this project.# Powered by the Pipelex extension (plxt / taplo engine).diff --git a/pipelex/reporting/reporting_manager.py b/pipelex/reporting/reporting_manager.pyindex 750a3cad8..267d5b272 100644--- a/pipelex/reporting/reporting_manager.py+++ b/pipelex/reporting/reporting_manager.py@@ -366,7 +366,7 @@ class ReportingManager(ReportingProtocol):log.warning(f"ReportingManager does not support reporting for inference job type: {type(inference_job).__name__}")@override- def generate_report(self, pipeline_run_id: str | None = None):+ def generate_report(self, pipeline_run_id: str | None = None, print_to_console: bool = True):cost_report_file_path: Path | None = Noneif self._reporting_config.is_generate_cost_report_file_enabled:ensure_path(self._reporting_config.cost_report_dir_path)@@ -388,6 +388,7 @@ class ReportingManager(ReportingProtocol):tokens_usages=registry.get_current_tokens_usage(),unit_scale=self._reporting_config.cost_report_unit_scale,cost_report_file_path=cost_report_file_path,+ print_to_console=print_to_console,)@overridediff --git a/pipelex/reporting/reporting_protocol.py b/pipelex/reporting/reporting_protocol.pyindex b772d09e1..451c056a5 100644--- a/pipelex/reporting/reporting_protocol.py+++ b/pipelex/reporting/reporting_protocol.py@@ -11,7 +11,7 @@ class ReportingProtocol(Protocol):def report_inference_job(self, inference_job: InferenceJobAbstract): ...- def generate_report(self, pipeline_run_id: str | None = None): ...+ def generate_report(self, pipeline_run_id: str | None = None, print_to_console: bool = True): ...def close_registry(self, pipeline_run_id: str): ...@@ -40,7 +40,7 @@ class ReportingNoOp(ReportingProtocol):pass@override- def generate_report(self, pipeline_run_id: str | None = None):+ def generate_report(self, pipeline_run_id: str | None = None, print_to_console: bool = True):pass@overridediff --git a/pipelex/system/configuration/configs.py b/pipelex/system/configuration/configs.pyindex 49460ffe2..dab8c7ad5 100644--- a/pipelex/system/configuration/configs.py+++ b/pipelex/system/configuration/configs.py@@ -97,7 +97,7 @@ class ReportingConfig(ConfigModel):cost_report_dir_path: strcost_report_base_name: strcost_report_extension: str- cost_report_unit_scale: float+ cost_report_unit_scale: Annotated[float, Field(gt=0)]class TracingBackend(StrEnum):diff --git a/tests/unit/pipelex/cogt/usage/test_cost_registry.py b/tests/unit/pipelex/cogt/usage/test_cost_registry.pyindex b0a0dbac4..869a4e13a 100644--- a/tests/unit/pipelex/cogt/usage/test_cost_registry.py+++ b/tests/unit/pipelex/cogt/usage/test_cost_registry.py@@ -430,3 +430,71 @@ class TestCostRegistry:output_cost=2.0,)assert total == 3.5++ def test_generate_report_print_to_console_false_skips_console(self, job_metadata: JobMetadata, mocker: MockerFixture):+ """When print_to_console=False, the console.print is not called."""+ mock_console = mocker.MagicMock()+ mocker.patch("pipelex.cogt.usage.cost_registry.get_console", return_value=mock_console)++ llm_tokens_usage = LLMTokensUsage(+ job_metadata=job_metadata,+ inference_model_name="test-model",+ inference_model_id="test-model-id",+ nb_tokens_by_category={+ TokenCategory.INPUT: 100,+ TokenCategory.OUTPUT: 50,+ TokenCategory.INPUT_CACHED: 20,+ },+ unit_costs={+ CostCategory.INPUT: 1000,+ CostCategory.INPUT_CACHED: 500,+ CostCategory.OUTPUT: 2000,+ },+ )++ CostRegistry.generate_report(+ pipeline_run_id="test-pipeline",+ tokens_usages=[llm_tokens_usage],+ unit_scale=1.0,+ cost_report_file_path=None,+ print_to_console=False,+ )++ mock_console.print.assert_not_called()++ def test_generate_report_print_to_console_false_still_writes_csv(self, job_metadata: JobMetadata, tmp_path: Path, mocker: MockerFixture):+ """When print_to_console=False, CSV file is still written if a path is provided."""+ mock_console = mocker.MagicMock()+ mocker.patch("pipelex.cogt.usage.cost_registry.get_console", return_value=mock_console)++ llm_tokens_usage = LLMTokensUsage(+ job_metadata=job_metadata,+ inference_model_name="test-model",+ inference_model_id="test-model-id",+ nb_tokens_by_category={+ TokenCategory.INPUT: 100,+ TokenCategory.OUTPUT: 50,+ TokenCategory.INPUT_CACHED: 20,+ },+ unit_costs={+ CostCategory.INPUT: 1000,+ CostCategory.INPUT_CACHED: 500,+ CostCategory.OUTPUT: 2000,+ },+ )++ csv_file = tmp_path / "csv_only.csv"+ CostRegistry.generate_report(+ pipeline_run_id="test-pipeline",+ tokens_usages=[llm_tokens_usage],+ unit_scale=1.0,+ cost_report_file_path=csv_file,+ print_to_console=False,+ )++ mock_console.print.assert_not_called()+ assert csv_file.exists()+ with open(csv_file, encoding="utf-8") as file:+ rows = list(csv.DictReader(file))+ assert len(rows) == 1+ assert rows[0][LLMTokenCostReportField.LLM_NAME] == "test-model"diff --git a/tests/unit/pipelex/system/test_reporting_config_validation.py b/tests/unit/pipelex/system/test_reporting_config_validation.pynew file mode 100644index 000000000..c74c7e3f1--- /dev/null+++ b/tests/unit/pipelex/system/test_reporting_config_validation.py@@ -0,0 +1,30 @@+import pytest+from pydantic import ValidationError++from pipelex.system.configuration.configs import ReportingConfig+++class TestReportingConfigValidation:+ @pytest.mark.parametrize("invalid_scale", [0.0, -1.0, -0.0001])+ def test_cost_report_unit_scale_must_be_positive(self, invalid_scale: float):+ """cost_report_unit_scale must be > 0 to prevent ZeroDivisionError in cost formatting."""+ with pytest.raises(ValidationError):+ ReportingConfig(+ is_log_costs_to_console=False,+ is_generate_cost_report_file_enabled=False,+ cost_report_dir_path="reports",+ cost_report_base_name="cost_report",+ cost_report_extension="csv",+ cost_report_unit_scale=invalid_scale,+ )++ def test_cost_report_unit_scale_positive_value_accepted(self):+ config = ReportingConfig(+ is_log_costs_to_console=False,+ is_generate_cost_report_file_enabled=False,+ cost_report_dir_path="reports",+ cost_report_base_name="cost_report",+ cost_report_extension="csv",+ cost_report_unit_scale=1.0,+ )+ assert config.cost_report_unit_scale == 1.0