Skip to content

Add support for priority tiers & better long-context surcharge#172

Merged
mike1858 merged 1 commit into
mainfrom
pb-analyzer
Jun 4, 2026
Merged

Add support for priority tiers & better long-context surcharge#172
mike1858 merged 1 commit into
mainfrom
pb-analyzer

Conversation

@mike1858

@mike1858 mike1858 commented Jun 4, 2026

Copy link
Copy Markdown
Member

Summary

This PR fixes and extends OpenAI GPT pricing support in Splitrail, with Piebald now using service-tier-aware pricing when its database records a service tier.

Changes

  • Corrected long-context pricing for gpt-5.4, gpt-5.4-pro, and gpt-5.5.
  • Changed those long-context models to use full-session bracket pricing instead of progressive tier pricing.
  • Added ServiceTier support to the model pricing layer:
    • Standard
    • Priority
    • Flex
    • Batch
  • Added per-service-tier pricing overrides to ModelInfo.
  • Added service-tier-aware cost helpers:
    • calculate_input_cost_for_service_tier
    • calculate_output_cost_for_service_tier
    • calculate_cache_cost_for_service_tier
    • calculate_total_cost_for_service_tier
  • Added Priority pricing for:
    • gpt-5.5
    • gpt-5.4
    • gpt-5.4-mini
  • Added Flex and Batch pricing for:
    • gpt-5.5
    • gpt-5.5-pro
    • gpt-5.4
    • gpt-5.4-mini
    • gpt-5.4-nano
    • gpt-5.4-pro
  • Updated the Piebald analyzer to read OpenAI service tiers from its generation config override tables:
    • override_gen_cfg_data_openai_responses.service_tier
    • override_gen_cfg_data_openai_completions.service_tier
  • Piebald now maps:
    • priorityServiceTier::Priority
    • flexServiceTier::Flex
    • batchServiceTier::Batch
    • unknown/null values → ServiceTier::Standard
  • Piebald now calculates estimated costs with calculate_total_cost_for_service_tier(...).

Why

OpenAI’s long-context GPT pricing says prompts above the 272k input-token threshold are priced at the long-context rate for the full session. Splitrail previously represented some of these prices as progressive tiers, which undercounted long-context sessions.

Additionally, OpenAI exposes different pricing for service tiers such as Priority, Flex, and Batch. Splitrail now has a pricing model that can represent these tiers, and Piebald can use that information when it is present in its database.

Notes

  • Existing cost helpers still default to Standard pricing, so existing analyzers continue to work unchanged.
  • Piebald is the only analyzer wired to detect service tiers in this PR.
  • Unknown service-tier values fall back to Standard pricing. This handles unsupported values like scale without inventing pricing behavior.
  • Piebald still normalizes OpenAI cached-input token reporting the same way as before; this PR only changes which pricing table is selected.

Verification

Ran:

cargo test --quiet analyzers::piebald::tests
cargo test --quiet models::tests::gpt
cargo build --quiet
cargo clippy --quiet -- -D warnings
cargo fmt --all --quiet

Summary by CodeRabbit

  • New Features
    • Added support for multiple service tiers (Standard, Priority, Flex, Batch) with corresponding pricing configurations.
    • Service tier information is now automatically extracted and integrated into cost calculations.
    • Updated supported models with service-tier-specific pricing options for improved cost accuracy.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e22d8c3a-13c8-4e04-82e8-ebdcda615636

📥 Commits

Reviewing files that changed from the base of the PR and between 838bdf9 and 49c02ce.

📒 Files selected for processing (2)
  • src/analyzers/piebald.rs
  • src/models.rs

📝 Walkthrough

Walkthrough

This PR adds service-tier support to model pricing and cost calculation. It introduces new ServiceTier and ServiceTierPricing types, extends model configuration to register per-tier pricing overrides, refactors cost APIs to select pricing by tier, and integrates service tier extraction in the piebald analyzer to compute tiered costs from database metadata.

Changes

Service-Tier Cost Model

Layer / File(s) Summary
Service Tier Type Definitions
src/models.rs
ServiceTier enum (Standard/Priority/Flex/Batch) and ServiceTierPricing struct introduced; ModelInfo extended with service_tiers: HashMap<ServiceTier, ServiceTierPricing>.
Model Configuration & Validation for Service Tiers
src/models.rs
validate_model_info validates service-tier entries; populate_defaults initializes service_tiers and registers GPT tier overrides; bracket_pricing changed to true for tiered pricing/caching; free tier model updated.
Service-Tier-Aware Cost Calculation APIs
src/models.rs
pricing_for_service_tier helper selects override or base pricing; new functions calculate_*_for_service_tier compute costs from tier-selected pricing; existing calculate_* reworked as Standard-tier wrappers.
Model Test Coverage for Service Tiers
src/models.rs
Test imports and fixtures updated; comprehensive coverage for tiered pricing, fallback behavior, and tier-missing cases.
Piebald Analyzer Service Tier Extraction & Costing
src/analyzers/piebald.rs, src/models.rs
PiebaldMessage gains optional service_tier field; SQL query joins override tables and selects tier via COALESCE; parse_service_tier helper normalizes strings to ServiceTier variants; message conversion calls calculate_total_cost_for_service_tier.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Piebald-AI/splitrail#167: Both PRs modify convert_messages in the piebald analyzer to affect cost computation (service-tier-driven calculation vs. cached-read token normalization).
  • Piebald-AI/splitrail#125: Both PRs extend cost/pricing APIs in src/models.rs with tiering support (service_tiers vs. bracket-based pricing).
  • Piebald-AI/splitrail#149: Both PRs modify GPT-5.4/5.5 default pricing and registry entries in src/models.rs.

Suggested reviewers

  • bl-ue

Poem

🐰 Tiers upon tiers, the pricing flows,
Standard, Priority—the model knows,
Flex and Batch join the cost brigade,
Service-tier logic, now properly made!
From database rows to calculations bright,

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pb-analyzer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mike1858
mike1858 enabled auto-merge (squash) June 4, 2026 00:24
@mike1858
mike1858 merged commit 9b8aa0b into main Jun 4, 2026
5 of 6 checks passed
@mike1858
mike1858 deleted the pb-analyzer branch June 4, 2026 00:25
This was referenced Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant