Content Estimation
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Content Estimation is a feature within the Recoup CLI that allows users to project the costs associated with the content creation pipeline before triggering actual production runs. This module provides developers and content managers with financial transparency by calculating expected costs based on specific parameters such as video count and advanced processing modes.
The estimation system acts as a pre-flight check, querying the Recoup API to return both per-unit and total cost projections. This ensures that users can stay within budget while configuring complex content creation tasks.
Sources: src/commands/content/estimateCommand.ts:1-29, src/commands/content.ts:1-12
Architecture and Data Flow
The estimation logic is encapsulated in the estimate subcommand, which is part of the broader content command group. It follows a standard CLI request-response pattern using the central HTTP client to communicate with the Recoup platform.
Command Structure
The estimate command is built using Commander.js and registered via the main entry point. It accepts several optional flags that modify the request sent to the backend.
Sources: src/commands/content/estimateCommand.ts:7-13, src/bin.ts:1-32
Execution Flow
- Input Parsing: The CLI parses user-provided options, specifically validating the
--batchcount as a positive integer. - API Request: A GET request is dispatched to the
/api/content/estimateendpoint. - Data Processing: The CLI receives a JSON response containing financial estimates.
- Output Rendering: Depending on the
--jsonflag, the data is either printed as a formatted string or raw JSON.
The following diagram illustrates the sequence of operations during an estimation request:
Configuration Options
The estimation tool supports multiple configuration flags to refine cost accuracy.
| Option | Type | Default | Description |
|---|---|---|---|
--lipsync | Boolean | false | Includes costs for lipsync processing. |
--batch <count> | Integer | 1 | The number of videos to estimate for. |
--compare | Boolean | false | Includes comparison profiles in the estimate. |
--json | Boolean | false | Outputs the raw API response in JSON format. |
Sources: src/commands/content/estimateCommand.ts:9-13, tests/commands/content.test.ts:68-83
Technical Implementation
Input Validation
The system utilizes a utility function parsePositiveInt to ensure the --batch parameter is valid before making a network request. If an invalid value (e.g., a string) is provided, the CLI throws an error and exits.
Sources: src/commands/content/estimateCommand.ts:15, tests/commands/content.test.ts:117-124
Client Interaction
The command leverages the centralized get function from src/client.ts. This client automatically handles authentication by injecting the x-api-key header and base URL from the environment configuration.
Sources: src/client.ts:11-38, tests/client.test.ts:24-38
API Response Schema
The CLI expects a response from /api/content/estimate with the following structure:
{
"status": "success",
"per_video_estimate_usd": 0.82,
"total_estimate_usd": 1.64
}
Sources: tests/commands/content.test.ts:69-73, src/commands/content/estimateCommand.ts:28-29
Error Handling
The estimation module implements robust error handling. If the API returns a non-OK status or the network request fails, the printError utility is invoked, which logs the error message to stderr and terminates the process with exit code 1.
Sources: src/output.ts:54-62, src/commands/content/estimateCommand.ts:32-34
Summary
Content Estimation provides a critical utility for cost management within the Recoup CLI. By leveraging the /api/content/estimate endpoint, it allows for precise financial planning across different batch sizes and feature sets (like lipsync). The modular design ensures that estimation logic remains consistent with the actual content creation parameters.