When a recycler lists EPR plastic credits on the Novus exchange, an AI suggests what to charge. But this endpoint never takes that number on faith. Scroll to watch one request travel from the click to the final rupee — and try the pricing desk yourself.
Every stage runs in order. The cheap safety checks come first, so a bad request never reaches the expensive AI call. Hover any stage.
Pick a plastic category, look at the live market the code would read from Supabase, then ask the AI for a price. Flip “let the AI go rogue” to see what happens when the model returns something wild — and how the clamp reins it in.
Return whatever the model says. One hallucinated answer — ₹0, or ₹9,999/kg — flows straight to a real seller and a real buyer. A single bad token becomes a real financial mistake on a live marketplace.
Bound the AI’s number to a band derived from the real floor and average before anyone sees it. The model still guides the price within reason, but it can never push a trade off a cliff.
First, the AI is forced to answer in a fixed shape — no fragile text parsing. Second, the one value that touches money is clamped. Here is the real code.
// Force the model to fill an exact shape, not write prose const suggestionSchema = z.object({ suggested_price_per_kg: z.number(), sell_speed: z.enum(['fast', 'moderate', 'slow']), reasoning: z.string(), }) const { object } = await generateObject({ model, schema: suggestionSchema, system, prompt, })
// Never trust output blindly — clamp to a sane band around the market. const lo = Math.max(0.01, floor * 0.5) const hi = Math.max(avg * 2, floor * 1.5, 1) const price = Math.min(hi, Math.max(lo, object.suggested_price_per_kg))