Skip to content

cost_calculator

cost_calculator

Cost calculator -- estimate monthly cloud API costs for common use cases.

Classes

CostEstimate dataclass

CostEstimate(provider: str, label: str, monthly_cost: float, annual_cost: float, input_cost: float, output_cost: float, total_calls_per_month: int)

Estimated cost for a provider given a usage scenario.

Scenario dataclass

Scenario(name: str, label: str, description: str, calls_per_month: int, avg_input_tokens: int, avg_output_tokens: int)

A prebuilt usage scenario.

Functions

estimate_monthly_cost

estimate_monthly_cost(calls_per_month: int, avg_input_tokens: int, avg_output_tokens: int, provider_key: str) -> CostEstimate

Estimate monthly cost for a provider given usage parameters.

Source code in src/openjarvis/server/cost_calculator.py
def estimate_monthly_cost(
    calls_per_month: int,
    avg_input_tokens: int,
    avg_output_tokens: int,
    provider_key: str,
) -> CostEstimate:
    """Estimate monthly cost for a provider given usage parameters."""
    pricing = CLOUD_PRICING.get(provider_key)
    if pricing is None:
        raise ValueError(f"Unknown provider: {provider_key}")

    total_input = calls_per_month * avg_input_tokens
    total_output = calls_per_month * avg_output_tokens

    input_cost = (total_input / 1_000_000) * pricing["input_per_1m"]
    output_cost = (total_output / 1_000_000) * pricing["output_per_1m"]
    monthly = input_cost + output_cost

    return CostEstimate(
        provider=provider_key,
        label=str(pricing["label"]),
        monthly_cost=monthly,
        annual_cost=monthly * 12,
        input_cost=input_cost,
        output_cost=output_cost,
        total_calls_per_month=calls_per_month,
    )

estimate_scenario

estimate_scenario(scenario_name: str) -> List[CostEstimate]

Estimate costs for all providers for a named scenario.

Source code in src/openjarvis/server/cost_calculator.py
def estimate_scenario(scenario_name: str) -> List[CostEstimate]:
    """Estimate costs for all providers for a named scenario."""
    scenario = SCENARIOS.get(scenario_name)
    if scenario is None:
        raise ValueError(f"Unknown scenario: {scenario_name}")
    return [
        estimate_monthly_cost(
            scenario.calls_per_month,
            scenario.avg_input_tokens,
            scenario.avg_output_tokens,
            provider_key,
        )
        for provider_key in CLOUD_PRICING
    ]

estimate_all_scenarios

estimate_all_scenarios() -> Dict[str, List[CostEstimate]]

Estimate costs for all scenarios and all providers.

Source code in src/openjarvis/server/cost_calculator.py
def estimate_all_scenarios() -> Dict[str, List[CostEstimate]]:
    """Estimate costs for all scenarios and all providers."""
    return {name: estimate_scenario(name) for name in SCENARIOS}