Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/ai-gateway/dynamic-routing.md
1# Dynamic Routing23Configure complex routing in dashboard without code changes. Use route names instead of model names.45## Usage67```typescript8const response = await client.chat.completions.create({9model: 'dynamic/smart-chat', // Route name from dashboard10messages: [{ role: 'user', content: 'Hello!' }]11});12```1314## Node Types1516| Node | Purpose | Use Case |17|------|---------|----------|18| **Conditional** | Branch on metadata | Paid vs free users, geo routing |19| **Percentage** | A/B split traffic | Model testing, gradual rollouts |20| **Rate Limit** | Enforce quotas | Per-user/team limits |21| **Budget Limit** | Cost quotas | Per-user spending caps |22| **Model** | Call provider | Final destination |2324## Metadata2526Pass via header (max 5 entries, flat only):27```typescript28headers: {29'cf-aig-metadata': JSON.stringify({30userId: 'user-123',31tier: 'pro',32region: 'us-east'33})34}35```3637## Common Patterns3839**Multi-model fallback:**40```41Start → GPT-4 → On error: Claude → On error: Llama42```4344**Tiered access:**45```46Conditional: tier == 'enterprise' → GPT-4 (no limit)47Conditional: tier == 'pro' → Rate Limit 1000/hr → GPT-4o48Conditional: tier == 'free' → Rate Limit 10/hr → GPT-4o-mini49```5051**Gradual rollout:**52```53Percentage: 10% → New model, 90% → Old model54```5556**Cost-based fallback:**57```58Budget Limit: $100/day per teamId59< 80%: GPT-460>= 80%: GPT-4o-mini61>= 100%: Error62```6364## Version Management6566- Save changes as new version67- Test with `model: 'dynamic/route@v2'`68- Roll back by deploying previous version6970## Monitoring7172Dashboard → Gateway → Dynamic Routes:73- Request count per path74- Success/error rates75- Latency/cost by path7677## Limitations7879- Max 5 metadata entries80- Values: string/number/boolean/null only81- No nested objects82- Route names: alphanumeric + hyphens83