cloudflare

Catching rogue AI behavior with identity-aware analytics (opens in new tab)

AI usage is difficult to govern without knowing both who made each request and what normal usage looks like for that person or agent. Cloudflare’s new Identity-aware AI Gateway and User Insights address this by attaching verified identities to requests and detecting behavior that significantly deviates from historical patterns. Together, they provide centralized visibility, per-user cost controls, and anomaly detection without requiring additional setup for traffic already routed through AI Gateway.

AI Gateway as a Central Control Plane

  • AI Gateway routes requests from applications, developer tools, and agent harnesses—including Claude Code, Codex, and GitHub Copilot—through one platform.
  • It provides centralized observability, security, governance, and spend management across providers such as OpenAI, Anthropic, Google, and Workers AI.
  • This centralization makes it possible to analyze usage consistently across both human users and automated agents.

Identity-Aware Requests with Cloudflare Access

  • The Cloudflare Access integration places a custom domain, such as ai.example.com, in front of the gateway.
  • Organizations can:
    • Authenticate users through SAML-compatible providers such as Okta or Microsoft Entra.
    • Apply access policies to specific users.
    • Avoid distributing Cloudflare API keys.
  • Each authenticated request includes the Access user ID as cf.user_id.
  • Administrators can filter logs, analytics, and spending by the actual requester rather than by a shared API key.
  • Per-user spend limits can assign each person a separate budget and either block requests or route them to cheaper models after the limit is reached.
  • Planned improvements will use identity-provider groups to control model access and spending—for example, granting frontier-model access to machine learning teams while limiting support teams.

User Insights and Behavioral Baselines

  • User Insights is available to all AI Gateway customers at no extra cost.
  • It analyzes existing gateway traffic without requiring additional configuration.
  • The feature builds behavioral profiles for every account, including both people and agents.
  • It tracks cost inefficiencies such as poor cache-hit rates and oversized context windows, but focuses primarily on whether usage is normal for that particular account.
  • Human users and automated agents are evaluated according to their own patterns:
    • Agents may have regular, predictable sessions.
    • Humans typically have more irregular prompts, timing, and session lengths.

Session-Based Anomaly Detection

  • User Insights evaluates sessions rather than individual requests, reducing noise from isolated events.
  • Each session is compared with the account’s rolling 95th-percentile session cost over the previous 30 days.
  • A session becomes a strong anomaly candidate when it exceeds twice that personal p95 baseline.
  • This relative comparison avoids misleading fixed thresholds:
    • A $500 session may be normal for a consistently heavy user.
    • A $50 session may be highly unusual for an agent that normally spends $5.
  • Baselines adjust over time as an account’s usage changes.

Combining Personal and Organization-Wide Thresholds

  • User Insights also applies an organization-wide p99 cost ceiling.
  • In the example analysis:
    • Most sessions cost less than $10.
    • The organizational p95 is $20.
    • The p99 is $200, meaning only 1% of sessions reach that amount.
  • Alerts are triggered only when a session is both:
    • More than twice the account’s personal p95.
    • Above the organization’s p99 ceiling.
  • This prevents alerts for:
    • Small-dollar spikes that are statistically unusual but not worth investigating.
    • Expensive sessions that are routine for a particular user.
  • A dollar floor also prevents tiny accounts from triggering alerts because of insignificant percentage increases.

Filtering for Rogue Behavior

  • The resulting interface presents a feed of accounts that have broken their established usage patterns.
  • This focuses administrators on potentially meaningful incidents instead of showing every unusual request.
  • The approach is designed to detect trusted users or agents that suddenly perform more of an already-authorized activity—behavior that traditional controls may not block because no new tool or forbidden action is involved.

Cloudflare’s recommendation is to route AI traffic through AI Gateway, authenticate it with Cloudflare Access, and use identity-based budgets alongside behavioral baselines. This combination helps organizations connect spending and activity to specific people or agents while concentrating investigations on statistically significant, high-impact deviations.