Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

LLM Gateway Observability, Spend Limits, Logging, and Human Feedback

How to observe model traffic, control AI spend, configure logs and Guardrails, and submit human feedback on gateway requests.

This page summarises Cloudflare AI Gateway documentation on observing LLM traffic, controlling cost, tuning what gets stored in logs, and attaching human feedback to individual requests. AI Gateway sits between your application and model providers so you can gather analytics, enforce budgets, and moderate content without rewriting provider SDKs.

AI Gateway observability: analytics, logs, and what each records

Section titled “AI Gateway observability: analytics, logs, and what each records”

AI Gateway records model requests routed through a gateway, including query-rewriting and response-generation calls and external embedding or reranking traffic.

AI Gateway records the model requests routed through your gateway. This includes all query-rewriting and response-generation calls, plus external-provider embedding and reranking calls.

Analytics: Track the number of requests, tokens used, cost, latency, and errors across your model calls. Logs: Inspect individual requests and responses, including the effective system prompt, rewritten queries, and generated answers.

— Cloudflare, Observe your model calls

The dashboard Analytics view tracks requests, token usage, costs, errors, and cached responses over time. Logging adds per-request detail: prompts and responses (unless you suppress payloads), provider, status, tokens, cost, duration, user agent, DLP matches, and Guardrails evaluation records when those features are on.

cf-aig-log-id: how to find the log ID for feedback or API calls

Section titled “cf-aig-log-id: how to find the log ID for feedback or API calls”

Every evaluated request can be tied to a log entry via the cf-aig-log-id response header (or the logId field in AI SDK providerMetadata.cloudflare). Treat the ID as an opaque string: new IDs are lowercase UUIDv7; older logs use 26-character ULIDs. The logs API accepts both.

New AI Gateway log IDs and request IDs are lowercase UUIDv7, such as 019a7b3e-5f2c-7c41-9d3e-2b8f6a1c4e07.

— Cloudflare, AI Gateway log IDs and request IDs now use UUIDv7

For a single-step gateway response, cf-aig-request-id, cf-aig-log-id, and cf-aig-event-id often share the same value unless you set your own cf-aig-event-id. See the Header Glossary.

Logging settings: full logs, metadata-only, and per-request headers

Section titled “Logging settings: full logs, metadata-only, and per-request headers”

Logs are enabled by default per gateway. You can change the default under gateway Settings or override behavior per request.

Header Effect
cf-aig-collect-log Bypass default: force save or skip the entire log entry for one request
cf-aig-collect-log-payload When logging is on, store or skip only request/response bodies; metadata (tokens, model, cost, duration) still records

The cf-aig-collect-log-payload header allows you to control whether the raw request and response bodies (payloads) are stored for a given request. Unlike cf-aig-collect-log, which controls the entire log entry, this header only affects payload storage — metadata such as token counts, model, provider, status code, cost, and duration will still be logged.

— Cloudflare, Logging

If cf-aig-collect-log is false, no log row is written regardless of cf-aig-collect-log-payload. Use an authenticated gateway so unauthorized traffic does not inflate log volume.

Accounts that created their first gateway before September 24, 2026 may use Legacy Logs (dashboard viewer and Logs API). Newer accounts follow Workers Logs pricing described on the Pricing page.

Custom metadata and cf.user_id from Cloudflare Access

Section titled “Custom metadata and cf.user_id from Cloudflare Access”

You can tag requests with up to five custom metadata entries (gateway limits). Keys starting with cf. are reserved; do not send your own cf.* keys.

When traffic reaches AI Gateway through an Access-protected custom domain, the verified Access user ID is stored as cf.user_id (JWT sub, not email). Service-token requests do not get cf.user_id. See Custom metadata and Cloudflare Access.

With identity-aware controls, you can set spend limits by authenticated user, control which gateways different users can access, filter logs by user, and build policies without passing user IDs from the client application. AI Gateway adds the verified Access user ID to request metadata as cf.user_id.

— Cloudflare, Identity-aware controls are now available in AI Gateway

Spend limits vs rate limiting: cost-based AI budgets

Section titled “Spend limits vs rate limiting: cost-based AI budgets”

Rate limiting caps request count. Spend limits track cumulative dollar cost from token usage and model pricing, then block with HTTP 429 when a budget is exhausted for the configured window.

Unlike rate limiting, which caps the number of requests, spend limits track actual dollar cost per request based on model pricing.

— Cloudflare, Spend limits

Rules scope by provider, model, and/or custom metadata (split by value for per-user buckets, or filter to one value). Up to 20 rules per gateway. Spend limits apply to Unified Billing and BYOK where pricing is known. Enforcement is eventually consistent—a burst of concurrent requests may briefly exceed the cap.

With Cloudflare Access, scope a rule to metadata key cf.user_id and Split by value so each authenticated user gets an independent budget (Set spend limits by user). Without Access, pass your own user_id (or similar) via cf-aig-metadata.

Negotiated rates can be reflected with the cf-aig-custom-cost header (Custom costs), including optional per_cache_read_token and per_cache_write_token. Custom costs apply only when the request hits the provider (cache hits report cost 0).

User Insights: per-user spend and anomaly signals

Section titled “User Insights: per-user spend and anomaly signals”

User Insights uses existing gateway traffic—no extra setup. Without identity in metadata or Access, usage appears under one anonymous bucket.

On the security side, User Insights baselines each user’s normal usage from their 95th percentile (p95) session cost over the last 30 days, then flags sessions that exceed both that baseline and an organization-level threshold.

— Cloudflare, Track AI spend and catch anomalous usage with User Insights

Optional Log classification (per gateway, requires Collect logs) powers task and model-fit analysis in User Insights; it may process stored prompts and responses.

Guardrails: moderate prompts and responses at the gateway

Section titled “Guardrails: moderate prompts and responses at the gateway”

Guardrails proxy traffic and evaluate prompts and/or responses against hazard categories (for example P1 prompt injection, S9 indiscriminate weapons). Actions are Flag, Ignore, or Block. Blocked prompts return code 2016; blocked responses return 2017 (Set up Guardrails).

Guardrails runs on Workers AI (Llama Guard 3 8B and related models), adds latency (often around 500 ms per evaluation), and does not fully enforce streaming responses on REST paths—see Usage considerations and Supported model types.

Human feedback: dashboard, REST API, and Worker bindings

Section titled “Human feedback: dashboard, REST API, and Worker bindings”

Human feedback is the share of logs marked thumbs up. It feeds evaluations metrics.

Human feedback measures the performance of your dataset based on direct human input. The metric is calculated as the percentage of positive feedback (thumbs up) given on logs, which are annotated in the Logs tab of the Cloudflare dashboard.

— Cloudflare, Add Human Feedback using Dashboard

Add human feedback in the Cloudflare dashboard

Section titled “Add human feedback in the Cloudflare dashboard”

Open your gateway Logs, expand a row, and choose thumbs up (feedback: 1) or thumbs down (feedback: -1). See Add Human Feedback using Dashboard.

Submit human feedback with the Cloudflare API

Section titled “Submit human feedback with the Cloudflare API”
  1. Obtain cf-aig-log-id from the response header, the List Gateway Logs GET API, or env.AI.aiGatewayLogId after env.AI.run() (binding holds only the last inference log ID).

  2. PATCH the log with token permission AI Gateway Write:

    curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/ai-gateway/gateways/$GATEWAY_ID/logs/$ID" \
    --request PATCH \
    --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    --json '{"feedback": 1}'

    Use "feedback": -1 for negative feedback; 0 means not evaluated.

  3. Confirm in the dashboard or with GET on the same log. Details: Add Human Feedback using API.

From a Worker, after env.AI.run() with a gateway option:

await env.AI.gateway("my-gateway").patchLog(myLogId, {
feedback: 1,
score: 100,
metadata: { user: "123" },
});

All patchLog fields are optional (feedback is -1, 0, or 1; score is 0–100). See Add human feedback using Worker Bindings and Worker Binding methods.

The cf-aig-cache-key header opts a request into caching and groups equivalent prompts (Caching). Cache is volatile under concurrent identical requests. Auto Router and User Insights “Potential Savings” highlight cheaper model fits for similar tasks.

  • Validating log IDs as ULID-only after the UUIDv7 migration.
  • Setting cf-aig-collect-log-payload: false but expecting prompts in the Logs UI (only metadata remains).
  • Sending custom metadata keys named cf.user_id from the client—they are stripped; use Access or a non-reserved key like user_id.
  • Expecting spend limits to stop a parallel burst instantly (eventual consistency).
  • Enabling Guardrails on stream: true without reading streaming enforcement limits.
  1. Send a test prompt through your gateway endpoint, then open AI Gateway in the Cloudflare dashboard, select the gateway, and confirm the request on Logs with model, tokens, and latency (coding agents verify step).
  2. In the response headers (or AI SDK providerMetadata.cloudflare.logId), copy cf-aig-log-id and confirm it matches the log row (Add Human Feedback using API).
  3. Review Analytics for cost and cache hit rate (Analytics); if you use Access, filter logs or User Insights by cf.user_id (User Insights).
  4. Optionally PATCH feedback 1 or -1 and refresh the log to verify the Feedback filter (Set up Evaluations).
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.