Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
fix(studio/pricing): long-context tier starts strictly above the threshold (#9527)
Mark Yanc6b5166f0a4d
diff --git a/studio/backend/core/inference/pricing.py b/studio/backend/core/inference/pricing.pyindex ea568b6ea1a..6886742a797 100644--- a/studio/backend/core/inference/pricing.py+++ b/studio/backend/core/inference/pricing.py@@ -244,11 +244,14 @@ def calculate_cost(provider: str, model: str, usage: dict[str, Any]) -> dict[strreturn out# Long-context tier: whole-turn flip (not per-token blend) once- # billable_input_tokens crosses the threshold.+ # billable_input_tokens crosses the threshold. Strictly above: OpenAI bills+ # "prompts with >272K input tokens" at the higher rate, so a prompt of+ # exactly 272,000 stays on the standard rate -- which is also what the+ # "(long-context >{lc_thresh})" label emitted below already claims.lc_thresh = prices.get("long_context_threshold")in_long_context_tier = (lc_thresh is not None- and out["billable_input_tokens"] >= int(lc_thresh)+ and out["billable_input_tokens"] > int(lc_thresh)and "long_context_input_per_mtok" in pricesand "long_context_output_per_mtok" in prices)diff --git a/studio/backend/tests/test_pricing_edge.py b/studio/backend/tests/test_pricing_edge.pyindex 1fcc428f903..4055b73a26a 100644--- a/studio/backend/tests/test_pricing_edge.py+++ b/studio/backend/tests/test_pricing_edge.py@@ -232,20 +232,22 @@ def test_openai_long_context_triggers_on_cache_creation_inflated_billable():assert _isclose(out["output_usd"], 1_000 / 1_000_000.0 * 45.0)-def test_openai_long_context_threshold_boundary_inclusive():- # Threshold is inclusive (>=).+def test_openai_long_context_threshold_boundary_exclusive():+ # Threshold is exclusive (>). OpenAI prices "prompts with >272K input+ # tokens" at 2x input / 1.5x output for the full session, so a prompt of+ # exactly 272,000 is still on the standard rate.out = calculate_cost("openai","gpt-5.5",{"input_tokens": 272_000, "output_tokens": 1_000},)- assert "long-context" in out["model_priced"]- out_lo = calculate_cost(+ assert "long-context" not in out["model_priced"]+ out_hi = calculate_cost("openai","gpt-5.5",- {"input_tokens": 271_999, "output_tokens": 1_000},+ {"input_tokens": 272_001, "output_tokens": 1_000},)- assert "long-context" not in out_lo["model_priced"]+ assert "long-context" in out_hi["model_priced"]# ── chat-style vs raw envelope parity at OpenAI long-context tier ──