Use case · Metered chat

A chat demo with the meter in view

One bounded prompt goes through the same endpoint the starter ships: identity, budget admission, credit reserve, provider call, settlement and a usage row. If this deployment has no provider, the demo says so instead of inventing a reply.

DemoMeteredLimited

No AI provider is configured

The endpoint needs an OpenAI-compatible base URL, key and model. Until they are set, no model call is made and no reply is invented.

AI_BASE_URLAI_API_KEYAI_MODEL

No response yet

This panel only shows text returned by a configured provider. It does not generate a placeholder answer.

What one request proves

The scope is deliberately narrow: one bounded chat completion, not an image or video workbench.

01

Identity first

A session or a scoped API key is required. The provider key stays on the server and never reaches the browser.

02

Budget before work

Per-user daily and monthly credits, request and minute limits, and concurrency leases are admitted in one D1 statement before the charge.

03

Settlement with a paper trail

Credits are reserved, the provider is called, and the ledger records the result. A definitive rejection refunds; an unknown outcome is kept for reconciliation.

What it does not do

The demo keeps the honest edges of the starter visible.

  • No image, video, voice or training workbench. Those need separate providers, UI and cost controls.
  • Credits are internal units. The page does not convert them into a dollar price or pretend to know a provider's contract.
  • A missing provider is a configuration state, not a model answer. The form is disabled and no placeholder text is shown.

Demo questions

Only when the deployment has a working OpenAI-compatible provider, credits are enabled and you are signed in. Otherwise the form is disabled and the page states which configuration is missing. It never shows a fabricated model reply.

Wire the same path in your clone

The feature guide and docs cover provider configuration, credit budgets, API keys, settlement and the Cloudflare deployment.