API Reference¶
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')[source]¶
Column mapping for request trace DataFrames.
- Parameters:
- 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.core.frame.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=())[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)
- unit_name¶
Name of capacity unit (e.g., “GSU”, “PTU”).
- Type:
Literal[‘GSU’, ‘PTU’, ‘capacity_unit’]
- 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 max_units_to_search < 1 or headroom_factor < 0.
- 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.core.frame.DataFrame
- latency_summary¶
Aggregate latency statistics.
- Type:
pandas.core.frame.DataFrame
- slack_summary¶
Spare capacity statistics by time window.
- Type:
pandas.core.frame.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.core.frame.DataFrame
- latency_summary¶
Latency statistics (for latency planning).
- Type:
pandas.core.frame.DataFrame | None
- request_level¶
Per-request results (for latency planning).
- Type:
pandas.core.frame.DataFrame | None
- class slosizer.schema.PaygoPricing(input_cost_per_million, output_cost_per_million)[source]¶
Per-token pricing for overflow traffic.
- 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.HybridPricingModel(provisioned, paygo)[source]¶
Combined pricing for hybrid capacity planning.
- Parameters:
provisioned (ProvisionedPricing)
paygo (PaygoPricing)
- provisioned¶
Hourly cost for provisioned capacity.
- paygo¶
Per-token pricing for overflow traffic.
- 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, 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_output_tokens_hourly, slack_summary, assumptions=<factory>)[source]¶
Results from hybrid capacity planning.
- Parameters:
provisioned_units (int)
unit_name (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_output_tokens_hourly (float)
slack_summary (DataFrame)
- slack_summary¶
Spare capacity statistics by time window.
- Type:
pandas.core.frame.DataFrame
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_unit is not set or if trace contains fewer than 2 requests.
- 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
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 is missing the avg_spare_fraction_1s 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:
Provider Adapters¶
Vertex AI¶
Google Cloud Vertex AI capacity profiles.
This module provides built-in capacity profiles for Vertex AI Generative AI models using the GSU (Generative Service Unit) provisioned throughput model.
See: https://cloud.google.com/vertex-ai/generative-ai/docs/provisioned-throughput/supported-models
- slosizer.providers.vertex.available_vertex_profiles()[source]¶
List available built-in Vertex AI model profiles.
- slosizer.providers.vertex.vertex_profile(model)[source]¶
Get a built-in Vertex AI capacity profile.
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/ai-services/openai/concepts/provisioned-throughput
- 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, 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) – Model identifier (e.g., “gpt-4.1”).
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.
notes (tuple[str, ...]) – Additional notes about the profile.
- Returns:
CapacityProfile configured for Azure OpenAI.
- Return type: