---
title: "Caveman vs Cloudflare AI Gateway for agent costs"
description: "Cloudflare AI Gateway controls model traffic at a hosted gateway. Caveman can reduce eligible context on the machine running your agent. If your problem is repeated tool output, try changing the paylo"
canonical: https://caveman.so/compare/cloudflare-ai-gateway
last-updated: 2026-09-07
---

# Caveman vs Cloudflare AI Gateway for agent costs

Cloudflare AI Gateway controls model traffic at a hosted gateway. Caveman can reduce eligible context on the machine running your agent. If your problem is repeated tool output, try changing the payload before deciding to change the hosted gateway.

This comparison concerns Cloudflare AI Gateway. Caveman's local proxy does not replace Workers, a CDN, DNS, or Cloudflare's application security services. Keep those decisions separate from AI usage optimization.

## What the gateway and proxy do

Cloudflare's [AI Gateway overview](https://developers.cloudflare.com/ai-gateway/) documents analytics, logging, caching, rate limiting, retries, and fallback behavior. Caveman's proxy focuses on local context handling and recovery, with additional Platform workflows available through private access.

| Job | Cloudflare AI Gateway | Caveman |
| --- | --- | --- |
| Observe model traffic | Gateway analytics and request logging | Local token reports and a separate Platform analysis path |
| Reuse a response | Gateway caching | A distinct decision from local context compression |
| Reduce a changing tool result | Depends on the application and configured path | Content-specific compression before inference |
| Keep originals available | Application's source-data and retention design | Local recovery store for published lossy views |
| Run inside a Worker | Cloudflare-native deployment environment | A desktop loopback proxy is not a Worker service |

## Caching and compression solve different repetition

A response cache helps when a request can safely reuse an earlier answer. An agent investigation often changes on every turn: it reads a new file, changes a test, then asks the model to interpret the next result. The repeated cost may be the old context carried into each new request.

Caveman targets eligible content in that context. It returns a smaller view and retains the original so the model can recover detail. That can be useful even when every final request is different enough to miss a response cache.

Provider prompt caching is a third mechanism. It reuses computation for a repeated prefix, and its counters and prices differ from a gateway response-cache hit. The [caching guide](/guides/prompt-caching) explains how to measure these mechanisms without counting the same effect twice.

## Where a local trial fits

For a coding agent on your machine, use a supported Caveman launcher or compress one command's output. You can test the value of smaller context before moving a production application.

For a Worker application, begin in a local development harness with recorded payloads. `127.0.0.1:8787` inside a hosted Worker does not point to your laptop. Replacing a hosted gateway URL with that address is not a deployment plan.

If you need hosted Caveman features, confirm the private-access deployment and integration contract before changing production traffic. The local tools are available independently.

## Keep controls when comparing routes

Cloudflare may be enforcing rate limits, logging rules, and retry behavior for your application. A direct-provider test through Caveman does not inherit those settings. Preserve them in the baseline and write down what would need a replacement before a full move.

Test the errors you rely on as well as the happy path. Confirm how cancellation, streaming, and fallback attempts appear in usage. A response cache can also hide whether a request reached the provider, which changes the evidence needed for an optimization claim.

## How to choose

Choose Caveman for a concrete context-reduction experiment around a supported local agent. Keep Cloudflare AI Gateway when its hosted controls already fit your application. Combine or replace layers only after you have measured the actual task and verified the required policies.

The [switching guide](/switch/cloudflare-ai-gateway) gives a local experiment, a mapping of controls, and rollback steps. We do not claim a production cost or latency win over Cloudflare without a matched workload and account-level evidence.

Sources: [Cloudflare AI Gateway](https://developers.cloudflare.com/ai-gateway/), [Caveman provider routes](https://docs.caveman.so/docs/proxy/providers), and [Caveman counting rules](https://docs.caveman.so/docs/counting).
