Normalize IdP membership into one trusted budget group.
Control AI spend
at the group level.
Use Cloudflare AI Gateway Dynamic Routing to translate trusted identity context into shared budgets, approved model choices, and predictable fallback behavior.
Expose task names, not a catalog of provider models.
Degrade to a lower-cost model or stop cleanly.
Put identity before inference.
Dynamic Routing evaluates request metadata; it does not query Entra ID, Okta, or another identity provider. A trusted application tier must resolve group membership and attach the canonical policy attributes.
User + group claims
groups: ["ai-standard"]
Normalize policy
budget_group: "standard"
Evaluate route
dynamic/netspi-assistant
Run selected model
fast / balanced / advanced
One entry point. Three policy tiers.
Select an illustrative group to see how a single route can branch into a group budget and a deliberately small model set. Group names and dollar values should be replaced during discovery.
General workforce
- Shared daily budget
- $25
- Budget pool value
group.general- Primary route
- Fast
- At limit
- Stop + explain
GENERAL
$25 / DAY
FAST
Low-cost default for summarization, drafting, and knowledge retrieval. Advanced models are not presented.
Set the rate node key to metadata.budget_group. Every request carrying the same normalized value consumes the same quota.
Add a second rate node keyed on metadata.user_id if one user should not consume the group allocation alone.
Terminate for a hard stop. A cheaper-model fallback preserves service, but continues spending and is therefore only a soft threshold.
Normalize first, route second.
Keep directory-specific identifiers out of route definitions. The application maps raw claims to stable policy tiers, then AI Gateway applies conditional and budget nodes.
Define precedence
If a user belongs to multiple groups, resolve exactly one effective tier. Prefer explicit priority such as research > delivery > general.
Attach trusted metadata
Send stable identifiers in cf-aig-metadata. Avoid sensitive directory attributes and stay within AI Gateway's five-entry metadata limit.
Branch to fixed limits
Each group branch leads to a cost-based rate node with its approved limit, window, primary model, and over-budget behavior.
Version and observe
Deploy route changes as versions, monitor spend and fallback rates, and retain an immediately reversible prior version.
const policy = resolvePolicy(validatedClaims.groups);
const metadata = {
user_id: hash(validatedClaims.subject),
budget_group: policy.budgetGroup,
model_tier: policy.modelTier,
workload: "workforce-assistant"
};
await fetch(AI_GATEWAY_URL, {
method: "POST",
headers: {
"cf-aig-authorization": `Bearer ${GATEWAY_TOKEN}`,
"cf-aig-metadata": JSON.stringify(metadata)
},
body: JSON.stringify({
model: "dynamic/netspi-assistant",
messages
})
});
{
"id": "budget-general",
"type": "rate",
"properties": {
"limitType": "cost",
"key": "metadata.budget_group",
"limit": 25,
"window": 86400
},
"outputs": {
"success": { "elementId": "model-fast" },
"fallback": { "elementId": "END" }
}
}
Important: the values above illustrate structure, not a final NetSPI budget recommendation. This hard-stop pattern returns an error at the limit; the application should translate it into a clear message. Establish limits from measured token volume, model pricing, concurrency, and business criticality.
Show capabilities, not catalogs.
A long provider model list creates decision fatigue and makes cost unpredictable. Give non-technical users a few stable, task-oriented choices while routes own the underlying model selection.
- Provider A / model-x-2026-08
- Provider A / model-x-mini
- Provider B / model-pro-latest
- Provider C / model-70b-fp8
- Provider D / reasoning-preview
- + 37 more models
Quick Assist
Draft, summarize, retrieve
Deep Analysis
Complex security reasoning
Code Review
Technical analysis
Curate what users see
The application presents approved route aliases such as Quick Assist. It never fetches or displays the provider catalog.
Prevent bypass
Keep provider and gateway credentials server-side. Accept only allowlisted route aliases at the proxy and reject arbitrary model strings.
Change models centrally
Point each route to a reviewed model set. Swap or roll back the implementation without retraining users or changing application code.
Launch with evidence, not guesses.
Budgets should evolve from observed demand. Begin with a narrow pilot, instrument decisions, and promote only after the fallback and cost behavior are understood.
Baseline
Inventory use cases, groups, provider keys, approved models, and expected daily volume.
Pilot
Run representative users with conservative limits. Capture cost per group, user, route, and workload.
Tune
Adjust budgets, model tiers, timeouts, retries, and fallback messaging from measured behavior.
Govern
Review monthly, test rollback, remove unused models, and investigate unexpected group or direct-model traffic.