Skip to main content
Pass 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

  1. 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 with 400 max_cost_exceeded and nothing runs:
    Lower max_output_tokens, pick cheaper candidates, or raise the cap.
  2. 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
As new models and rails launch, ninja/auto can improve without changing your integration while the cap remains fixed.