@tpmjs/tools-workflow-cost-estimate
Estimates cost of running a workflow based on step count and estimated API calls
Export "workflowCostEstimate" not found in module
Last checked: 1/1/2026, 8:18:30 AM
Test @tpmjs/tools-workflow-cost-estimate (workflowCostEstimate) with AI-powered execution
0/2000 characters
Install this tool and use it with the AI SDK
npm install @tpmjs/tools-workflow-cost-estimatepnpm add @tpmjs/tools-workflow-cost-estimateyarn add @tpmjs/tools-workflow-cost-estimatebun add @tpmjs/tools-workflow-cost-estimatedeno add npm:@tpmjs/tools-workflow-cost-estimateimport { workflowCostEstimate } from '@tpmjs/tools-workflow-cost-estimate';import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { workflowCostEstimate } from '@tpmjs/tools-workflow-cost-estimate';
const result = await generateText({
model: openai('gpt-4o'),
tools: { workflowCostEstimate },
prompt: 'Your prompt here...',
});
console.log(result.text);Available configuration options
workflowobjectWorkflow object with steps array
costPerStepnumberCost per step in dollars (default: 0.01)
Try to auto-extract schema from the package
Estimates cost of running a workflow based on step count, step types, and estimated API calls.
npm install @tpmjs/tools-workflow-cost-estimate
import { workflowCostEstimateTool } from '@tpmjs/tools-workflow-cost-estimate'; const workflow = { steps: [ { id: 'fetch-data', type: 'api' }, { id: 'process-llm', type: 'llm' }, { id: 'save-db', type: 'database' } ] }; const result = await workflowCostEstimateTool.execute({ workflow, costPerStep: 0.01 // $0.01 base rate }); console.log(result); // { // totalCost: 0.045, // stepCount: 3, // breakdown: [ // { stepId: 'fetch-data', stepCost: 0.01, ... }, // { stepId: 'process-llm', stepCost: 0.03, ... }, // { stepId: 'save-db', stepCost: 0.005, ... } // ], // currency: 'USD', // metadata: { ... } // }
const workflow = { steps: [ { id: 'bulk-fetch', type: 'api', estimatedCalls: 10 // This step makes 10 API calls }, { id: 'process-each', type: 'llm', estimatedCalls: 10 // Process each item with LLM } ] }; const result = await workflowCostEstimateTool.execute({ workflow, costPerStep: 0.01 }); console.log(result.totalCost); // 0.4 (10 * 0.01 + 10 * 0.03)
const workflow = { steps: [ { id: 'expensive-api', customCost: 0.05, // Override with exact cost estimatedCalls: 5 }, { id: 'cheap-transform', type: 'transform' // Uses type multiplier } ] }; const result = await workflowCostEstimateTool.execute({ workflow }); console.log(result.totalCost); // 0.255 (0.05 * 5 + 0.01 * 0.5)
The tool applies these multipliers to the base cost:
| Step Type | Multiplier | Example Cost (base $0.01) |
|---|---|---|
llm-large | 5.0x | $0.05 |
llm | 3.0x | $0.03 |
compute | 2.0x | $0.02 |
api | 1.0x | $0.01 |
llm-small | 1.0x | $0.01 |
http | 1.0x | $0.01 |
transform | 0.5x | $0.005 |
database | 0.5x | $0.005 |
validation | 0.3x | $0.003 |
storage | 0.3x | $0.003 |
default | 1.0x | $0.01 |
interface CostEstimate { totalCost: number; // Total estimated cost in USD stepCount: number; // Number of steps in workflow breakdown: StepCostBreakdown[]; // Per-step cost details currency: string; // Currency code (always 'USD') metadata: { averageCostPerStep: number; // Mean cost per step totalEstimatedCalls: number; // Sum of all API calls baseRate: number; // Base cost rate used }; } interface StepCostBreakdown { stepId: string; stepIndex: number; stepName?: string; stepType?: string; estimatedCalls: number; costPerCall: number; stepCost: number; }
const workflow = await buildWorkflow(); const estimate = await workflowCostEstimateTool.execute({ workflow, costPerStep: 0.02 // Conservative estimate }); if (estimate.totalCost > BUDGET_LIMIT) { console.warn(`Workflow exceeds budget: $${estimate.totalCost}`); // Optimize or reject workflow }
const workflowA = { steps: [/* ... */] }; const workflowB = { steps: [/* ... */] }; const costA = await workflowCostEstimateTool.execute({ workflow: workflowA }); const costB = await workflowCostEstimateTool.execute({ workflow: workflowB }); console.log(`Workflow A: $${costA.totalCost}`); console.log(`Workflow B: $${costB.totalCost}`); console.log(`Savings: $${Math.abs(costA.totalCost - costB.totalCost)}`);
const estimate = await workflowCostEstimateTool.execute({ workflow }); console.log(`Total: $${estimate.totalCost}\n`); console.log('Breakdown by step:'); for (const step of estimate.breakdown) { console.log( ` ${step.stepName || step.stepId}: $${step.stepCost} ` + `(${step.estimatedCalls} calls × $${step.costPerCall})` ); }
const estimate = await workflowCostEstimateTool.execute({ workflow }); // Find most expensive steps const expensiveSteps = estimate.breakdown .filter(step => step.stepCost > 0.05) .sort((a, b) => b.stepCost - a.stepCost); console.log('Steps to optimize:'); expensiveSteps.forEach(step => { console.log(` - ${step.stepId}: $${step.stepCost}`); });
// Adjust base rate based on user tier const userTierRates = { free: 0.015, pro: 0.01, enterprise: 0.005 }; const estimate = await workflowCostEstimateTool.execute({ workflow, costPerStep: userTierRates[userTier] }); console.log(`Cost for ${userTier} tier: $${estimate.totalCost}`);
const complexWorkflow = { steps: [ { id: 'fetch-documents', name: 'Fetch user documents', type: 'api', estimatedCalls: 20 }, { id: 'extract-text', name: 'Extract text from PDFs', type: 'compute', estimatedCalls: 20 }, { id: 'summarize-llm', name: 'Generate summaries', type: 'llm-large', estimatedCalls: 20 }, { id: 'sentiment-analysis', name: 'Analyze sentiment', type: 'llm-small', estimatedCalls: 20 }, { id: 'store-results', name: 'Save to database', type: 'database', estimatedCalls: 20 }, { id: 'send-notification', name: 'Send email notification', customCost: 0.001, // Exact cost from email provider estimatedCalls: 1 } ], metadata: { name: 'Document Processing Pipeline', version: '2.0.0' } }; const estimate = await workflowCostEstimateTool.execute({ workflow: complexWorkflow, costPerStep: 0.01 }); console.log(`Total cost: $${estimate.totalCost}`); console.log(`Average per step: $${estimate.metadata.averageCostPerStep}`); console.log(`Total API calls: ${estimate.metadata.totalEstimatedCalls}`);
try { await workflowCostEstimateTool.execute({ workflow: { steps: [] } }); } catch (error) { // Valid - empty workflow is allowed } try { await workflowCostEstimateTool.execute({ workflow: null }); } catch (error) { console.error(error.message); // "Workflow must be an object" } try { await workflowCostEstimateTool.execute({ workflow: { steps: [{ id: 'step1', estimatedCalls: -5 }] } }); } catch (error) { console.error(error.message); // "Step 'step1' has invalid estimatedCalls..." }
MIT
Downloads/month
0
Quality Score