API Reference¶
Use plan_hybrid_capacity() for the normal fixed-demand case. It minimizes the cost of provisioned capacity and paygo overflow subject to an optional hard SLO. Because the trace fixes gross value, this choice also maximizes profit without requiring a business-value estimate.
Use plan_profit_capacity() only when you need absolute expected profit or a priced SLO. Use compare_profit_scenarios() only when separate model forecasts justify different request traces or request values.
Schema¶
Core data structures for capacity planning.
Core data structures for capacity planning.
This module defines the schema classes used throughout slosizer for representing request traces, capacity profiles, SLO targets, and planning results.
- class slosizer.schema.OutputTokenSource(*values)[source]¶
Source for output token counts in capacity planning.
- OBSERVED¶
Use actual observed output token counts from trace data.
- MAX_OUTPUT_TOKENS¶
Use max_output_tokens limit for worst-case planning.
- class slosizer.schema.LatencyMetric(*values)[source]¶
Latency metric for SLO evaluation.
- E2E¶
End-to-end latency including baseline model latency and queue delay.
- QUEUE_DELAY¶
Queue delay only, excluding baseline model latency.
- class slosizer.schema.RequestSchema(time_col='ts', class_col='class_name', input_tokens_col='input_tokens', cached_input_tokens_col='cached_input_tokens', output_tokens_col='output_tokens', thinking_tokens_col='thinking_tokens', max_output_tokens_col='max_output_tokens', latency_col='latency_s', request_id_col='request_id', request_model_col='request_model', response_model_col='response_model', service_tier_col='service_tier', business_value_col='business_value')[source]¶
Column mapping for request trace DataFrames.
- Parameters:
time_col (str)
class_col (str | None)
input_tokens_col (str)
cached_input_tokens_col (str | None)
output_tokens_col (str)
thinking_tokens_col (str | None)
max_output_tokens_col (str | None)
latency_col (str | None)
request_id_col (str | None)
request_model_col (str | None)
response_model_col (str | None)
service_tier_col (str | None)
business_value_col (str | None)
- class slosizer.schema.RequestTrace(frame, schema, provider=None, model=None, region=None, metadata=<factory>)[source]¶
Normalized request trace with canonical columns.
- Parameters:
- frame¶
DataFrame with canonical columns (arrival_s, input_tokens, etc.).
- Type:
pandas.DataFrame
- schema¶
Original schema used to parse the trace.
- metadata¶
Additional trace metadata.
- Type:
collections.abc.Mapping[str, Any]
- class slosizer.schema.CapacityProfile(provider, model, unit_name, throughput_per_unit, purchase_increment=1, min_units=1, input_weight=1.0, cached_input_weight=0.0, output_weight=4.0, thinking_weight=4.0, long_input_threshold=None, long_input_input_weight=None, long_input_cached_input_weight=None, long_input_output_weight=None, long_input_thinking_weight=None, source='', notes=(), deployment_type='provisioned', region=None, effective_from=None, verified_on=None)[source]¶
Provider-specific capacity configuration.
Defines how tokens translate to reserved capacity units and the constraints on purchasing those units.
- Parameters:
provider (str)
model (str)
unit_name (Literal['GSU', 'PTU', 'capacity_unit'])
throughput_per_unit (float | None)
purchase_increment (int)
min_units (int)
input_weight (float)
cached_input_weight (float)
output_weight (float)
thinking_weight (float)
long_input_threshold (int | None)
long_input_input_weight (float | None)
long_input_cached_input_weight (float | None)
long_input_output_weight (float | None)
long_input_thinking_weight (float | None)
source (str)
deployment_type (str)
region (str | None)
effective_from (date | None)
verified_on (date | None)
- unit_name¶
Name of capacity unit (e.g., “GSU”, “PTU”).
- Type:
Literal[‘GSU’, ‘PTU’, ‘capacity_unit’]
- effective_from¶
Date on which the provider facts became effective.
- Type:
datetime.date | None
- verified_on¶
Date on which the source was last checked.
- Type:
datetime.date | None
- class slosizer.schema.LatencySLO(threshold_s, percentile=0.99, metric=LatencyMetric.E2E)[source]¶
Latency service level objective.
- metric¶
Latency metric to measure (E2E or QUEUE_DELAY).
- Raises:
ValueError – If threshold_s <= 0 or percentile not in (0, 1).
- Parameters:
threshold_s (float)
percentile (float)
metric (LatencyMetric)
- class slosizer.schema.ThroughputTarget(percentile=0.99, max_overload_probability=None, windows_s=(1.0, 5.0, 30.0))[source]¶
Throughput-based capacity planning target.
- Raises:
ValueError – If percentile not in (0, 1) or max_overload_probability not in [0, 1].
- Parameters:
- class slosizer.schema.LatencyTarget(slo)[source]¶
Latency-based capacity planning target.
- Parameters:
slo (LatencySLO)
- slo¶
The latency SLO to meet.
- class slosizer.schema.BaselineLatencyModel(intercept_s=0.15, input_token_s=3e-05, cached_input_token_s=8e-06, output_token_s=0.0009, thinking_token_s=0.0007)[source]¶
Linear model for baseline request latency.
Predicts latency as a linear combination of token counts, useful for estimating processing time independent of queueing.
- Parameters:
- class slosizer.schema.PlanOptions(output_token_source=OutputTokenSource.OBSERVED, max_units_to_search=200, headroom_factor=0.0, baseline_latency_model=None)[source]¶
Options for capacity planning.
- output_token_source¶
Use OBSERVED or MAX_OUTPUT_TOKENS for planning.
- baseline_latency_model¶
Custom latency model; if None, one is fitted.
- Type:
- Raises:
ValueError – If the output-token source is unsupported,
max_units_to_searchis less than one, orheadroom_factoris negative.- Parameters:
output_token_source (OutputTokenSource)
max_units_to_search (int)
headroom_factor (float)
baseline_latency_model (BaselineLatencyModel | None)
- class slosizer.schema.SimulationResult(units, unit_name, request_level, latency_summary, slack_summary, assumptions)[source]¶
Results from a capacity simulation.
- Parameters:
- request_level¶
Per-request simulation results.
- Type:
pandas.DataFrame
- latency_summary¶
Aggregate latency statistics.
- Type:
pandas.DataFrame
- slack_summary¶
Spare capacity statistics by time window.
- Type:
pandas.DataFrame
- class slosizer.schema.PlanResult(objective, target, recommended_units, unit_name, metrics, slack_summary, latency_summary=None, request_level=None, assumptions=<factory>)[source]¶
Results from capacity planning.
- Parameters:
- slack_summary¶
Spare capacity statistics.
- Type:
pandas.DataFrame
- latency_summary¶
Latency statistics (for latency planning).
- Type:
pandas.DataFrame | None
- request_level¶
Per-request results (for latency planning).
- Type:
pandas.DataFrame | None
- class slosizer.schema.PaygoPricing(input_cost_per_million, output_cost_per_million, cached_input_cost_per_million=None, thinking_cost_per_million=None)[source]¶
Per-token pricing for overflow traffic.
- cached_input_cost_per_million¶
Cost per million cached input tokens. If omitted, the regular input price is used.
- Type:
float | None
- thinking_cost_per_million¶
Cost per million separately reported reasoning tokens. If omitted, the regular output price is used.
- Type:
float | None
- Raises:
ValueError – If costs are negative.
- Parameters:
- class slosizer.schema.ProvisionedPricing(cost_per_unit_hour)[source]¶
Hourly cost for provisioned capacity.
- Raises:
ValueError – If cost is negative.
- Parameters:
cost_per_unit_hour (float)
- class slosizer.schema.RateCard(provisioned, paygo=None, currency='USD', provider=None, model=None, region=None, deployment_type=None, effective_from=None, effective_to=None, verified_on=None, source='')[source]¶
Effective-dated model and deployment prices.
- Parameters:
- provisioned¶
Hourly cost for provisioned capacity.
- paygo¶
Per-token pricing for overflow traffic, if applicable.
- Type:
slosizer.schema.PaygoPricing | None
- effective_from¶
First date on which the rate card applies.
- Type:
datetime.date | None
- effective_to¶
Last date on which the rate card applies.
- Type:
datetime.date | None
- verified_on¶
Date on which the price source was last checked.
- Type:
datetime.date | None
- validate_for(profile)[source]¶
Validate that explicitly scoped prices match a capacity profile.
- Parameters:
profile (CapacityProfile)
- Return type:
None
- class slosizer.schema.HybridTarget(strategy, provision_percentile=None, latency_slo=None)[source]¶
Target for hybrid capacity planning.
- strategy¶
Planning strategy - “cost_optimal” or “percentile_split”.
- Type:
Literal[‘cost_optimal’, ‘percentile_split’]
- provision_percentile¶
Percentile to provision for (required if strategy=”percentile_split”).
- Type:
float | None
- latency_slo¶
Optional latency SLO constraint.
- Type:
slosizer.schema.LatencySLO | None
- Raises:
ValueError – If strategy is “percentile_split” but provision_percentile is not set, or if provision_percentile is not in (0, 1).
- Parameters:
strategy (Literal['cost_optimal', 'percentile_split'])
provision_percentile (float | None)
latency_slo (LatencySLO | None)
- class slosizer.schema.HybridPlanResult(provisioned_units, unit_name, currency, provisioned_cost_hourly, paygo_cost_hourly, total_cost_hourly, full_provision_units, full_provision_cost_hourly, savings_vs_full_provision, savings_percent, overflow_fraction, overflow_input_tokens_hourly, overflow_cached_input_tokens_hourly, overflow_output_tokens_hourly, overflow_thinking_tokens_hourly, slack_summary, assumptions=<factory>)[source]¶
Results from hybrid capacity planning.
- Parameters:
provisioned_units (int)
unit_name (str)
currency (str)
provisioned_cost_hourly (float)
paygo_cost_hourly (float)
total_cost_hourly (float)
full_provision_units (int)
full_provision_cost_hourly (float)
savings_vs_full_provision (float)
savings_percent (float)
overflow_fraction (float)
overflow_input_tokens_hourly (float)
overflow_cached_input_tokens_hourly (float)
overflow_output_tokens_hourly (float)
overflow_thinking_tokens_hourly (float)
slack_summary (DataFrame)
- slack_summary¶
Spare capacity statistics by time window.
- Type:
pandas.DataFrame
- class slosizer.schema.ProfitTarget(latency_slo, slo_policy='hard', value_per_request=None, slo_violation_cost_per_request=0.0)[source]¶
Optional absolute-profit or priced-SLO objective.
business_valueis gross contribution before inference and SLO costs. It can be supplied as one value for every request or through the canonicalbusiness_valuetrace column. It does not change the request count or timing. UseHybridTargetfor fixed-demand cost optimization under a hard SLO; that common case does not require business value. With one trace and a hard SLO, business value changes reported profit but not recommended capacity.- Parameters:
latency_slo (LatencySLO)
slo_policy (Literal['hard', 'priced'])
value_per_request (float | None)
slo_violation_cost_per_request (float)
- latency_slo¶
Latency promise used to classify good and bad requests.
- slo_policy¶
hardexcludes plans that miss the SLO;pricedassigns the stated penalty to every bad request.- Type:
Literal[‘hard’, ‘priced’]
- class slosizer.schema.ProfitPlanResult(recommended_units, unit_name, currency, gross_value_hourly, provisioned_cost_hourly, slo_violation_cost_hourly, expected_profit_hourly, slo_attainment, candidate_plans, assumptions=<factory>)[source]¶
Profit-maximizing reserved-capacity plan and its candidate frontier.
- Parameters:
- class slosizer.schema.ProfitScenario(name, trace, profile, pricing, target)[source]¶
Named model forecast for optional cross-model economic comparison.
Each trace is an external demand forecast. The package does not estimate how a model changes request count, timing, token mix, or burstiness.
- Parameters:
name (str)
trace (RequestTrace)
profile (CapacityProfile)
pricing (RateCard)
target (ProfitTarget)
Ingestion¶
Request trace parsing and normalization.
Request trace ingestion and normalization.
This module provides functions to convert raw DataFrames into normalized RequestTrace objects with canonical column names.
- slosizer.ingest.from_dataframe(df, *, schema, provider=None, model=None, region=None, validate=True, metadata=None)[source]¶
Create a RequestTrace from a DataFrame.
Normalizes column names and validates data according to the schema.
- Parameters:
df (DataFrame) – Source DataFrame with request data.
schema (RequestSchema) – Column mapping for the DataFrame.
provider (str | None) – Cloud provider name.
model (str | None) – Model identifier.
region (str | None) – Deployment region.
validate (bool) – Whether to validate data constraints.
metadata (dict[str, Any] | None) – Additional trace metadata.
- Returns:
Normalized RequestTrace.
- Raises:
ValueError – If required columns are missing or validation fails.
- Return type:
Simulation¶
Capacity simulation for queue-based latency modeling.
Capacity simulation for queue-based latency modeling.
This module simulates request processing with finite capacity to estimate latency distributions and capacity utilization.
- slosizer.simulation.fit_baseline_latency_model(trace)[source]¶
Fit a linear latency model from observed latencies.
Uses ordinary least squares to fit latency as a function of token counts. Coefficients are constrained to be non-negative. Only rows with valid (non-NaN) latency values are used for fitting.
- Parameters:
trace (RequestTrace) – Request trace with observed latencies.
- Returns:
Fitted baseline latency model, or default model if insufficient data.
- Return type:
- slosizer.simulation.bucket_required_units(frame, profile, *, units, windows_s, output_token_source)[source]¶
Compute required capacity units per time bucket.
Divides the trace into fixed-width time windows and calculates the capacity units needed to serve all requests in each window.
- Parameters:
frame (DataFrame) – DataFrame with canonical columns.
profile (CapacityProfile) – Capacity profile with throughput settings.
units (int) – Reserved capacity units to compare against.
output_token_source (str) – Source for output tokens.
- Returns:
DataFrame with required_units, spare_units, and overflow_units per bucket.
- Raises:
ValueError – If profile.throughput_per_unit is not set.
- Return type:
DataFrame
- slosizer.simulation.bucket_with_tokens(frame, profile, *, units, window_s, output_token_source)[source]¶
Compute required units and token counts per time bucket.
Similar to bucket_required_units but also tracks raw token counts per bucket for overflow cost calculation. Uses a single window size for efficiency.
- Parameters:
frame (DataFrame) – DataFrame with canonical columns.
profile (CapacityProfile) – Capacity profile with throughput settings.
units (int) – Reserved capacity units to compare against.
window_s (float) – Time window size in seconds.
output_token_source (str) – Source for output tokens.
- Returns:
DataFrame with required_units, overflow metrics, and token counts per bucket.
- Raises:
ValueError – If profile.throughput_per_unit is not set.
- Return type:
DataFrame
- slosizer.simulation.summarize_slack(slack_table)[source]¶
Summarize spare capacity statistics by time window.
- Parameters:
slack_table (DataFrame) – Output from bucket_required_units.
- Returns:
DataFrame with aggregate statistics per window size.
- Return type:
DataFrame
- slosizer.simulation.simulate_capacity(trace, profile, *, units, options=None, windows_s=(1.0, 5.0, 30.0))[source]¶
Simulate request processing with fixed capacity.
Models a simple FIFO queue where requests arrive and are processed at a rate determined by the reserved capacity.
- Parameters:
trace (RequestTrace) – Request trace to simulate.
profile (CapacityProfile) – Capacity profile with throughput settings.
units (int) – Number of reserved capacity units.
options (PlanOptions | None) – Planning options including output token source.
windows_s (tuple[float, ...]) – Time window sizes for slack analysis.
- Returns:
SimulationResult with latency and slack statistics.
- Raises:
ValueError – If
profile.throughput_per_unitis not set,unitsis less than one, or the trace has fewer than two distinct arrival times.- Return type:
Planning¶
Capacity planning algorithms.
Capacity planning algorithms.
This module provides functions to determine optimal reserved capacity based on throughput or latency targets.
- slosizer.planning.plan_capacity(trace, profile, target, *, options=None)[source]¶
Determine optimal reserved capacity for a target.
Searches over candidate capacity levels to find the minimum that satisfies the given throughput or latency target.
- Parameters:
trace (RequestTrace) – Request trace representing workload.
profile (CapacityProfile) – Capacity profile for the target provider/model.
target (ThroughputTarget | LatencyTarget) – Throughput or latency target to meet.
options (PlanOptions | None) – Planning options.
- Returns:
PlanResult with recommended capacity and metrics.
- Raises:
ValueError – If profile.throughput_per_unit is not set.
TypeError – If target is not a ThroughputTarget or LatencyTarget.
- Return type:
- slosizer.planning.compare_scenarios(scenarios, profile, targets, *, options=None)[source]¶
Compare capacity requirements across scenarios and targets.
- Parameters:
scenarios (Mapping[str, RequestTrace]) – Named request traces to compare.
profile (CapacityProfile) – Capacity profile for planning.
targets (Sequence[ThroughputTarget | LatencyTarget]) – Throughput and/or latency targets.
options (PlanOptions | None) – Planning options.
- Returns:
DataFrame with planning results for each scenario/target combination.
- Return type:
DataFrame
Economics¶
Optional absolute-profit, priced-SLO, and cross-model analysis.
Optional absolute-profit and cross-model planning.
The economic planner keeps business value and SLO policy separate from provider capacity facts and rate cards. It evaluates every legal provisioned-capacity choice and maximizes expected hourly contribution after inference and SLO costs. For the common fixed-demand case with a hard SLO, use hybrid cost optimization; gross value is constant and does not need to be supplied.
- slosizer.economics.plan_profit_capacity(trace, profile, pricing, target, *, options=None)[source]¶
Choose reserved capacity that maximizes expected hourly profit.
Profit is expected gross business value minus provisioned inference cost and, for a priced SLO, the expected cost of requests that miss the latency threshold. A hard SLO instead removes noncompliant capacity choices.
The function intentionally does not apply
headroom_factorafter finding an optimum, because doing so would no longer maximize the stated objective. Forecast uncertainty should be represented by workload scenarios.- Parameters:
trace (RequestTrace) – Model-specific request trace or replay scenario.
profile (CapacityProfile) – Capacity facts for the model and deployment.
pricing (RateCard) – Effective rate card. Only its provisioned price is used here.
target (ProfitTarget) – Business value and SLO policy.
options (PlanOptions | None) – Simulation and search options.
headroom_factormust be zero.
- Returns:
Recommended capacity with the complete candidate frontier.
- Raises:
ValueError – If required economic inputs are absent or inconsistent.
RuntimeError – If no searched capacity choice satisfies a hard SLO.
- Return type:
- slosizer.economics.compare_profit_scenarios(scenarios, *, options=None)[source]¶
Compare externally forecast model scenarios by expected hourly profit.
The function does not estimate demand effects. Each scenario’s trace defines its request count, timing, token mix, and burstiness.
- Parameters:
scenarios (list[ProfitScenario])
options (PlanOptions | None)
- Return type:
DataFrame
Catalogs¶
Versioned provider capacity facts.
Load versioned provider capacity facts from TOML catalogs.
Plotting¶
Visualization functions.
Visualization functions for capacity planning results.
- slosizer.plotting.plot_latency_vs_units(trace, profile, *, units, options=None, target=None, path=None)[source]¶
Plot latency percentiles as a function of reserved capacity.
- Parameters:
trace (RequestTrace) – Request trace to simulate.
profile (CapacityProfile) – Capacity profile.
options (PlanOptions | None) – Planning options.
target (LatencyTarget | None) – Optional latency target to show as horizontal line.
path (str | Path | None) – Optional path to save the figure.
- Return type:
None
- slosizer.plotting.plot_required_units_distribution(trace, profile, *, windows_s=(1.0, 5.0, 30.0), options=None, path=None)[source]¶
Plot histogram of required capacity units per time window.
- Parameters:
trace (RequestTrace) – Request trace to analyze.
profile (CapacityProfile) – Capacity profile.
options (PlanOptions | None) – Planning options.
path (str | Path | None) – Optional path to save the figure.
- Return type:
None
- slosizer.plotting.plot_capacity_tradeoff(comparison, *, path=None)[source]¶
Plot recommended capacity across scenarios and targets.
- slosizer.plotting.plot_slack_tradeoff(comparison, *, path=None)[source]¶
Plot spare capacity fraction across scenarios and targets.
- Parameters:
- Raises:
ValueError – If comparison has no average spare-fraction column.
- Return type:
None
Synthetic Workloads¶
Synthetic workload generation for testing.
Synthetic workload generation for testing and demonstration.
- slosizer.synthetic.optimize_trace(trace)[source]¶
Apply prompt optimization to reduce token usage.
Simulates the effect of prompt engineering and caching improvements by reducing input, output, and thinking tokens.
- Parameters:
trace (RequestTrace) – Original request trace.
- Returns:
Optimized trace with reduced token counts.
- Return type:
- slosizer.synthetic.make_synthetic_trace(*, horizon_s=14400, seed=42, scenario='baseline')[source]¶
Generate a synthetic request trace for testing.
- Parameters:
- Returns:
Synthetic RequestTrace.
- Raises:
ValueError – If
horizon_sis less than one second orscenariois not"baseline"or"optimized".- Return type:
Provider Adapters¶
Vertex AI¶
Google Cloud Vertex AI capacity profiles.
The reviewed model facts live in slosizer/data/vertex.toml so new models and
provider changes do not require editing planning logic.
- slosizer.providers.vertex.available_vertex_profiles()[source]¶
List reviewed built-in Vertex AI model profiles.
- slosizer.providers.vertex.vertex_profile(model)[source]¶
Get a reviewed Vertex AI capacity profile by exact model identifier.
Azure OpenAI¶
Azure OpenAI PTU capacity profiles.
This module provides a factory function for creating Azure OpenAI capacity profiles using the PTU (Provisioned Throughput Unit) model.
Azure PTU throughput is workload-sensitive and must be calibrated per deployment. See: https://learn.microsoft.com/en-us/azure/foundry/openai/how-to/provisioned-throughput-sizing
- slosizer.providers.azure.azure_profile(model, *, throughput_per_unit, purchase_increment=1, min_units=1, input_weight=1.0, cached_input_weight=0.0, output_weight=4.0, thinking_weight=4.0, deployment_type='global_provisioned', region=None, notes=())[source]¶
Create an Azure OpenAI PTU capacity profile.
Azure PTU capacity varies by workload, so profiles must be calibrated using the Azure capacity calculator and benchmark data.
- Parameters:
model (str) – Exact model identifier from the current Foundry sizing table.
throughput_per_unit (float) – Tokens per second per PTU.
purchase_increment (int) – Minimum PTU increment for purchasing.
min_units (int) – Minimum number of PTUs.
input_weight (float) – Token weight for input tokens.
cached_input_weight (float) – Token weight for cached input tokens.
output_weight (float) – Token weight for output tokens.
thinking_weight (float) – Token weight for thinking tokens.
deployment_type (str) – Global, data-zone, or regional provisioned offering.
region (str | None) – Deployment region when the calibration is region-specific.
notes (tuple[str, ...]) – Additional notes about the profile.
- Returns:
CapacityProfile configured for Azure OpenAI.
- Return type: