Skip to content

Automate browser based workflows with AI

[Oncall] Deprecate public workflow run total_cost (#6108)

Marc Kelechavae42716149b12
diff --git a/skyvern-frontend/src/api/types.ts b/skyvern-frontend/src/api/types.ts
index f6cc53e76..b5bc1f3c9 100644
--- a/skyvern-frontend/src/api/types.ts
+++ b/skyvern-frontend/src/api/types.ts
@@ -594,6 +594,8 @@ export type WorkflowRunStatusApiResponse = {
downloaded_file_urls: Array<string> | null;
total_steps: number | null;
total_cost: number | null;
+ credits_used: number;
+ cached_credits_used: number;
task_v2: TaskV2 | null;
workflow_title: string | null;
browser_session_id: string | null;
@@ -628,6 +630,8 @@ export type WorkflowRunStatusApiResponseWithWorkflow = {
downloaded_file_urls: Array<string> | null;
total_steps: number | null;
total_cost: number | null;
+ credits_used: number;
+ cached_credits_used: number;
task_v2: TaskV2 | null;
workflow_title: string | null;
browser_session_id: string | null;
diff --git a/skyvern/forge/sdk/workflow/models/workflow.py b/skyvern/forge/sdk/workflow/models/workflow.py
index 3b591dd18..dad401140 100644
--- a/skyvern/forge/sdk/workflow/models/workflow.py
+++ b/skyvern/forge/sdk/workflow/models/workflow.py
@@ -2,7 +2,7 @@ from datetime import datetime
from enum import StrEnum
from typing import Any, List
-from pydantic import BaseModel, field_validator
+from pydantic import BaseModel, Field, field_validator
from typing_extensions import deprecated
from skyvern.forge.sdk.db.enums import WorkflowRunTriggerType
@@ -313,7 +313,13 @@ class WorkflowRunResponseBase(BaseModel):
downloaded_file_urls: list[str] | None = None
outputs: dict[str, Any] | None = None
total_steps: int | None = None
- total_cost: float | None = None
+ total_cost: float | None = Field(
+ default=None,
+ deprecated=True,
+ description="Deprecated. Public workflow-run responses no longer expose cost; use credits_used fields instead.",
+ )
+ credits_used: int = 0
+ cached_credits_used: int = 0
task_v2: TaskV2 | None = None
workflow_title: str | None = None
browser_session_id: str | None = None
diff --git a/skyvern/forge/sdk/workflow/service.py b/skyvern/forge/sdk/workflow/service.py
index 4ca45b48b..9acd3e4a6 100644
--- a/skyvern/forge/sdk/workflow/service.py
+++ b/skyvern/forge/sdk/workflow/service.py
@@ -5200,27 +5200,12 @@ class WorkflowService:
parameters_with_value = {wfp.key: wfrp.value for wfp, wfrp in workflow_parameter_tuples}
total_steps = None
- total_cost = None
if include_step_count or include_cost:
- if include_cost:
- # step counts and block list are independent — fetch in parallel.
- (step_count, completed_step_count), workflow_run_blocks = await asyncio.gather(
- app.DATABASE.tasks.get_step_counts_by_task_ids(
- task_ids=[task.task_id for task in workflow_run_tasks], organization_id=organization_id
- ),
- app.DATABASE.observer.get_workflow_run_blocks(
- workflow_run_id=workflow_run_id, organization_id=organization_id
- ),
- )
- text_prompt_blocks = [
- block for block in workflow_run_blocks if block.block_type == BlockType.TEXT_PROMPT
- ]
- # This is a temporary cost calculation.
- total_cost = 0.05 * (completed_step_count + len(text_prompt_blocks))
- else:
- step_count, _ = await app.DATABASE.tasks.get_step_counts_by_task_ids(
- task_ids=[task.task_id for task in workflow_run_tasks], organization_id=organization_id
- )
+ # `include_cost` is retained as a legacy alias for callers that
+ # previously received `total_steps` alongside deprecated cost data.
+ step_count, _ = await app.DATABASE.tasks.get_step_counts_by_task_ids(
+ task_ids=[task.task_id for task in workflow_run_tasks], organization_id=organization_id
+ )
total_steps = step_count
return WorkflowRunResponseBase(
@@ -5249,7 +5234,9 @@ class WorkflowService:
downloaded_file_urls=downloaded_file_urls,
outputs=outputs,
total_steps=total_steps,
- total_cost=total_cost,
+ total_cost=None,
+ credits_used=workflow_run.credits_used,
+ cached_credits_used=workflow_run.cached_credits_used,
workflow_title=workflow.title,
browser_session_id=workflow_run.browser_session_id,
browser_profile_id=workflow_run.browser_profile_id,
diff --git a/skyvern/services/webhook_service.py b/skyvern/services/webhook_service.py
index cc51fb68b..bec51b1f5 100644
--- a/skyvern/services/webhook_service.py
+++ b/skyvern/services/webhook_service.py
@@ -158,7 +158,9 @@ def build_sample_workflow_run_payload(run_id: str | None = None) -> dict:
downloaded_file_urls=[],
outputs={"result": "success", "data": "Sample workflow output"},
total_steps=5,
- total_cost=0.05,
+ total_cost=None,
+ credits_used=5,
+ cached_credits_used=2,
workflow_title="Sample Workflow",
browser_session_id="pbs_sample_123456",
errors=[],
diff --git a/tests/unit/test_webhook_timestamps.py b/tests/unit/test_webhook_timestamps.py
index 94d465497..e5e36f293 100644
--- a/tests/unit/test_webhook_timestamps.py
+++ b/tests/unit/test_webhook_timestamps.py
@@ -12,6 +12,7 @@ from datetime import datetime, timezone
from skyvern.forge.sdk.workflow.models.workflow import WorkflowRunResponseBase, WorkflowRunStatus
from skyvern.schemas.runs import RunStatus, RunType, WorkflowRunRequest, WorkflowRunResponse
+from skyvern.services.webhook_service import build_sample_workflow_run_payload
def _make_status_response() -> WorkflowRunResponseBase:
@@ -113,3 +114,11 @@ def test_webhook_replay_payload_includes_timestamps() -> None:
assert payload_dict["queued_at"] is not None, "queued_at should not be null in webhook replay payload"
assert payload_dict["started_at"] is not None, "started_at should not be null in webhook replay payload"
assert payload_dict["finished_at"] is not None, "finished_at should not be null in webhook replay payload"
+
+
+def test_sample_workflow_webhook_payload_uses_public_credit_fields() -> None:
+ payload = build_sample_workflow_run_payload("wr_sample_test")
+
+ assert payload["total_cost"] is None
+ assert payload["credits_used"] == 5
+ assert payload["cached_credits_used"] == 2