routing.max_cost_usd to reject routes whose published execution envelope exceeds your request budget. Keep the model decision explicit with model or models; use ninja/auto when you want NinjaChat to choose.
Parameters
How the cap is enforced
-
Before any provider call, the gateway computes the maximum token hold for the request: your input estimate plus the output ceiling, priced at the candidate models’ metered rates. If that hold is above
max_cost_usd, the request is rejected with400 max_cost_exceededand nothing runs:Lowermax_output_tokens, pick cheaper candidates, or raise the cap. -
At settle time, the metered charge is capped at
max_cost_usd. Usage priced above the cap is absorbed by NinjaChat — it is logged, never billed to you.
The cap is a guardrail, not a prediction of the final charge. Actual billing uses measured tokens and is returned as
cost_usd. Read live model pricing when you need to forecast a workload.Where it shines
Cost control per request without maintaining a model list. A tiered product can map plan → budget — treat these as starting points, not guarantees: a plan’s real headroom still depends on how long its users’ messages run.Python SDK
ninja/auto can improve without changing your integration while the cap remains fixed.