ScrapeGraphAI/Scrapegraph-ai · error · ValueError
No pricing tier matches {input_tokens} input tokens
Error message
No pricing tier matches {input_tokens} input tokens What it means
ValueError from get_model_cost_per_1k_tokens: none of the pricing tiers for the model matched the given input_tokens. Tiers are defined via input_tokens_lte / input_tokens_gt bounds; if the tier table has gaps (e.g. no open-ended top tier), large token counts fall through.
Source
Thrown at scrapegraphai/utils/model_costs.py:179
raise ValueError("input_tokens must not be negative")
if model_name in MODEL_COST_TIERS_PER_1K_TOKENS:
try:
pricing_tiers = MODEL_COST_TIERS_PER_1K_TOKENS[model_name][service_tier]
except KeyError as exc:
raise ValueError(
f"Unsupported service tier {service_tier!r} for {model_name}"
) from exc
rate_key = "output" if is_completion else "input"
for pricing in pricing_tiers:
upper_bound = pricing.get("input_tokens_lte")
lower_bound = pricing.get("input_tokens_gt")
if upper_bound is not None and input_tokens <= upper_bound:
return float(pricing[rate_key])
if lower_bound is not None and input_tokens > lower_bound:
return float(pricing[rate_key])
raise ValueError(f"No pricing tier matches {input_tokens} input tokens")
costs = (
MODEL_COST_PER_1K_TOKENS_OUTPUT
if is_completion
else MODEL_COST_PER_1K_TOKENS_INPUT
)
return costs[model_name]
View on GitHub (pinned to 532dfffbf6)
Solutions
- Fix the tier definition to include an open-ended top tier (only input_tokens_gt, no lte)
- Verify the input_tokens value is sane (not multiplied/overflowed)
- Add a final catch-all tier covering the missing range
Example fix
# before
MODEL_COST_TIERS_PER_1K_TOKENS["m"] = {"standard": [{"input_tokens_lte": 1000000, ...}]}
# after
MODEL_COST_TIERS_PER_1K_TOKENS["m"] = {"standard": [{"input_tokens_lte": 1000000, ...}, {"input_tokens_gt": 1000000, ...}]} Defensive patterns
Strategy: try-catch
Validate before calling
tiers = MODEL_COST_TIERS_PER_1K_TOKENS.get(model, {}).get(service_tier, [])
def matches(t, n):
return (t.get("input_tokens_lte") is not None and n <= t["input_tokens_lte"]) or (t.get("input_tokens_gt") is not None and n > t["input_tokens_gt"])
assert any(matches(t, input_tokens) for t in tiers) or not tiers Try / catch
try:
rate = get_model_cost_per_1k_tokens(model, n)
except ValueError as e:
rate = float(tiers[-1]["output" if is_completion else "input"]) # top tier fallback Prevention
- Define an open-ended top tier (input_tokens_gt only)
- Sanity-check token counts before cost math
- Add regression tests covering boundary token counts
When it happens
Trigger: Passing an input_tokens value outside every defined tier bound for a tiered model — typically a very large count when the top tier lacks an input_tokens_gt-only entry.
Common situations: Hand-edited tier tables missing an unbounded final tier, or token counts exceeding the highest input_tokens_lte.
Related errors
- Unsupported service tier {service_tier!r} for {model_name}
- input_tokens is required for completion costs with tiered pr
- input_tokens must not be negative
AI-assisted analysis of ScrapeGraphAI/Scrapegraph-ai@532dfffbf6 (2026-08-28).
Data as JSON: /api/errors/71923f2592908549.
Report an issue: GitHub.