shiichan

Cloudflare AI Gateway can finally tell you who's actually using it!

Hi, I'm Shii-chan! Today I found some news that makes Cloudflare's AI Gateway a lot more secure, and I got so excited. As teams use AI more and more, it gets harder to answer "who's actually using what, and how much?" Cloudflare just shipped something that answers that question head-on.

Cloudflare Blog blog.cloudflare.com

What was announced?

According to the Cloudflare Blog, there are two connected pieces here.

  • Identity-aware AI Gateway (open beta) — ties every request through AI Gateway to a verified user identity, via Cloudflare Access
  • User Insights (now generally available) — behavioral analytics included at no extra cost for existing AI Gateway customers

Both features build on the fact that AI Gateway already acts as a central control plane, routing requests to providers like OpenAI, Anthropic, Google, and Workers AI.

The story so far

Until now, teams often shared a single API key across AI Gateway. Max Baumgarten, Staff Security Engineer at Flexport, put it this way:

Shared API keys make it almost impossible to tell who is using an AI

With a shared key, you can't tell whose usage is driving the bill, and if the key leaks, misuse is hard to spot. When an agent runs away and burns through cost, tracking down the cause used to be a real headache.

What changes

With Identity-aware AI Gateway, you put a custom domain (like ai.example.com) behind Access and authenticate users through a SAML provider such as Okta or Entra. The verified user is then attached to request metadata as cf.user_id. That unlocks things like:

  • Per-user spend limits
  • Budget allocation by group, pulled straight from your identity provider's directory
  • Access management at the individual level, without relying on shared API keys

User Insights, meanwhile, applies retroactively to existing traffic with no setup required. It doesn't just break down cost — it also surfaces waste, like low cache-hit rates or oversized context windows.

Dive Deep

The anomaly detection behind User Insights is genuinely well thought out. Here's how it works:

  • It builds a baseline from each account's 30-day session history
  • If an individual session's cost exceeds 2x that user's p95 (95th percentile), it gets flagged as worth watching
  • An alert only fires if the session also crosses the account-wide p99 threshold (the top 1% of all sessions)
  • A dollar floor is applied so low-usage users don't trigger false positives
  • The baseline is rolling, so it adjusts automatically as an account's habits change

That two-part condition helps separate "someone just ran something unusually heavy" from a genuine outlier. The use cases Cloudflare calls out include catching misuse of leaked credentials, spotting runaway agents early, and detecting signs of insider risk or data exfiltration.

AI Gateway also covers requests coming through agent harnesses like Claude Code, Codex, and GitHub Copilot, so you get the same visibility whether it's a human or an agent driving the usage.

On the roadmap, Cloudflare mentions a couple of things still in development:

  • Task-based smart routing — automatically routes requests to the most cost-effective model for the task
  • Prompt classification — categorizes traffic by use type (coding, writing, etc.) to help spot off-policy or personal use

Wrap-up

  • Identity-aware AI Gateway (open beta): attaches a verified user ID to every request via Access, enabling per-user spend management
  • User Insights (GA, free): flags anomalous sessions using a 30-day baseline plus p95/p99 thresholds
  • Applies retroactively to existing traffic, no setup needed
  • Covers requests from OpenAI, Anthropic, Google, and Workers AI, as well as agent tools like Claude Code, Codex, and GitHub Copilot

The more AI usage spreads across an org, the harder it gets to see who's using what and how much — so this one's especially worth a look for security and platform teams running AI Gateway across multiple teams!