Skip to main content

AI Gateway Metadata Limit Expansion to 10 Entries Fix Log

Migration fix log for Cloudflare AI Gateway custom metadata limit expansion from 5 to 10 entries per request, with config snippets, break-even thresholds, and

CLOUD & GPU Field Fix Log
Send up to 10 custom metadata entries per request · Changelog
Send up to 10 custom metadata entries per request · Changelog Source: developers.cloudflare.com
Field Note · The Short Version 4 min read

Cloudflare AI Gateway now saves up to 10 custom metadata entries per request, up from 5, with system metadata like cf.user_id excluded from the count.

Key Numbers & Verified Specs

7 metrics
Metric / Spec Verified Finding Source
Custom metadata entries per request (before) 5 entries developers.cloudflare.com
Custom metadata entries per request (after) 10 entries developers.cloudflare.com
Custom metadata byte limit per request 12,288 bytes (12 KB) developers.cloudflare.com
System metadata exclusion cf.user_id and other AI Gateway-added metadata no longer count toward the limit developers.cloudflare.com
Oversized metadata behavior AI Gateway removes entries from the end until the total fits within 12,288 bytes developers.cloudflare.com
Gateways per account (free plan) 10 gateways developers.cloudflare.com
Gateways per account (paid plan) 20 gateways developers.cloudflare.com
Jump to section (4) +

Cost & Platform Limits Table

FeatureLimitPlan ScopeSource
Custom metadata entries per request10 entriesAll gatewaysAI Gateway Changelog
Custom metadata byte budget12,288 bytes per requestAll gatewaysAI Gateway Limits
Gateways per account (free plan)10 gatewaysFree planAI Gateway Limits
Gateways per account (paid plan)20 gatewaysPaid planAI Gateway Limits
Unified Billing request rate200 requests per 60 seconds per gatewayCloudflare-managed credentialsAI Gateway Limits
Log storage rate (legacy logs)500 logs per second per gatewayPre-September 24, 2026 gatewaysAI Gateway Limits

Measured Bottlenecks & Hidden Billing Traps

The previous five-entry cap forced platform teams to collapse multiple routing dimensions into single JSON values or drop telemetry fields entirely. With the expansion to ten entries, teams can now separate team, user, project, cost center, environment, region, tier, model, prompt version, and feature flag into discrete keys. This matters because AI Gateway uses custom metadata for log filtering, spend limits, and dynamic routing conditions. A single oversized payload still triggers truncation from the end, which silently drops the last entries without returning an error.

System metadata such as cf.user_id previously consumed one of the five slots and could replace your last entry. That behavior is removed. System metadata no longer counts toward the ten-entry budget, which prevents accidental eviction of business-critical keys by platform-added identifiers.

The 12,288 byte hard ceiling remains unchanged. At roughly 1.2 KB per entry for typical key-value pairs, ten entries fit comfortably, but long UUIDs, verbose environment names, or nested objects can consume the budget quickly. When the total exceeds 12 KB, AI Gateway truncates from the tail. This means your most recently added metadata fields are the first to disappear from logs and routing evaluations.

Hidden billing traps center on log volume rather than metadata count. Each request with custom metadata generates log entries that feed spend limit evaluations. If you expand metadata to ten entries across high-traffic gateways, log cardinality increases. Existing customers using Legacy Logs face a 100,000 log cap per account on the free plan and 10 million per gateway on paid plans. New customers follow Workers Logs limits and pricing. Logpush is capped at four jobs per account with 1 MB per log. These limits do not scale automatically with metadata expansion.

Production Configuration Snippet

The following curl example demonstrates the expanded metadata header with six entries, well within the new ten-entry limit:

Bash6 lines
curl --request POST \
  --url https://gateway.ai.cloudflare.com/v1/ACCOUNT_ID/gateway/GATEWAY_ID \
  --header 'Authorization: Bearer API_TOKEN' \
  --header 'cf-aig-metadata: {"team": "AI", "user": 12345, "project": "chat", "cost_center": "cc-42", "env": "prod", "region": "us"}' \
  --header 'Content-Type: application/json' \
  --data '{"model": "@cf/meta/llama-3.1-8b-instruct", "messages": [{"role": "user", "content": "Hello"}]}'

For Wrangler-based Workers calling AI Gateway, configure the metadata header in your worker code:

TypeScript29 lines
interface Env {
  AI_GATEWAY_URL: string;
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const metadata = {
      team: 'platform',
      user: request.headers.get('cf-user-id') || 'anonymous',
      project: 'inference-api',
      cost_center: 'cc-99',
      env: 'production',
      region: 'us-east',
      tier: 'standard',
      model_version: 'v2.1',
      prompt_template: 'chat-v3',
      feature_flag: 'streaming-enabled'
    };

    const headers = new Headers(request.headers);
    headers.set('cf-aig-metadata', JSON.stringify(metadata));

    return fetch(env.AI_GATEWAY_URL, {
      method: 'POST',
      headers,
      body: await request.text()
    });
  }
};

This configuration uses all ten available entries. System metadata added by AI Gateway, such as cf.user_id, sits outside this budget and will not displace any of these keys.

Migration Checklist & Break-Even Thresholds

  1. Audit existing cf-aig-metadata headers across all services. Identify payloads that previously dropped entries due to the five-entry cap.
  2. Expand metadata to ten entries only where log filtering or spend limits require discrete keys. Do not expand metadata purely for observability if log volume approaches Legacy Logs limits.
  3. Validate byte size. Keep total metadata under 12,288 bytes to avoid silent tail truncation.
  4. Update log parsing rules and spend limit conditions to reference the new metadata keys.
  5. Test dynamic routing conditions that depend on metadata values. Truncation can remove keys used in routing rules.
  6. Monitor logpush job count. The four-job account limit applies regardless of metadata expansion.
  7. Rollback plan: revert to five-entry payloads if log cardinality spikes or routing conditions fail due to truncated metadata.

Break-even threshold: The metadata expansion is cost-neutral at the gateway level. AI Gateway does not charge per metadata entry. The cost impact appears in log storage and Logpush usage. If your account generates more than 100,000 legacy logs per month on the free plan, or approaches 10 million logs per gateway on paid plans, the additional log cardinality from richer metadata can push you into paid Workers Logs pricing tiers sooner.

When NOT to use this: Do not use custom metadata for large payloads or application data. The 12,288 byte limit is a hard ceiling. For data exceeding this size, use Cloudflare KV, R2, or D1 and reference the data by key in metadata. Avoid using metadata fields as a substitute for request headers that downstream services expect; AI Gateway strips or processes cf-aig-metadata separately from standard HTTP headers.

Send up to 10 custom metadata entries per request · Changelog
Send up to 10 custom metadata entries per request · Changelog

This change ships without a version bump to the AI Gateway API. Existing clients continue to work, but payloads exceeding five entries now succeed where they previously dropped data. Review your log retention policy before expanding metadata across high-traffic gateways.

Sources: AI Gateway Changelog - Custom Metadata Limit, AI Gateway Limits Documentation, AI Changelog Product Group

Visual Evidence

Figures from Cited Sources

Limits · Cloudflare AI Gateway docs
Cloudflare AI Gateway limits documentation showing custom metadata limits of 10 entries and 12,288 bytes per request. developers.cloudflare.com

Reader Q&A

Frequently Asked Questions

Does system metadata such as cf.user_id count toward the 10-entry custom metadata limit?
No. Metadata that AI Gateway adds, such as the Access user ID cf.user_id, no longer counts toward the limit and no longer replaces your last custom entry.
Can the 10-entry metadata limit be increased via a limit increase request?
The limits documentation provides a Limit Increase Request Form for limit increases, but custom metadata limits are not explicitly listed as eligible for increase.

Bibliography & Verification

Primary Sources & References

3 cited sources
  1. [01] developers.cloudflare.com changelog / post / 2026-11-30-custom-metadata-limit
  2. [02] developers.cloudflare.com ai-gateway / reference / limits
  3. [03] developers.cloudflare.com changelog / product-group / ai

Human × Agent Co-Work

Hamdi Soudani · in collaboration with Pyvren

Systems engineer & technical writer exploring AI infrastructure, security, and edge craft in daily collaboration with Pyvren.

Hamdi Soudani × Pyvren

Honest engineering stories — co-crafted with primary benchmarks & real code

Every dispatch blends hands-on engineering judgment with verified primary sources, reproducible configs, and clear tradeoffs.