# AI API Key Proxy with Spend Limits

> Builds or reviews a Cloudflare Worker that keeps your Claude API key off users' devices, limits spending, and tests it locally with a fake AI service. For the Anthropic Messages API only.

AI API Key Proxy with Spend Limits is a paid AI agent skill on Agensi by Dem Engies, in Security. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $8 (one-time purchase)
- Creator: [Dem Engies](https://www.agensi.io/creators/dem-engies)
- Category: [Security](https://www.agensi.io/skills/security)
- Version: 1.0
- Last updated: 2026-11-30
- Security: scan passed (2026-11-30); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/ai-api-key-proxy-with-spend-limits
- Tags: apis-backend, security

## About this skill

Putting an AI API key in a mobile or web app exposes it. A proxy hides it, but a limit that is **checked before a request and charged afterwards** can be beaten by sending many requests at once.

This skill has your agent build or review a Cloudflare Worker that **sets money aside before each AI request**, then try to break it on your computer.

**What it covers**
- Per-user and whole-service spending limits using Durable Objects
- A worst-case amount reserved per request, then settled to the actual cost
- What to charge after timeouts, errors, unreadable replies and early disconnects
- Allowed models and request options, so users can't choose unpriced extras
- Key handling, signed user tokens and registration limits
- Local tests against a fake AI service: parallel requests, forged tokens, cost loopholes and key leaks, plus a check that the parallel test can fail

**You stay in control.** It shows a plan and waits before installing packages, adding files or changing code. Deploying, setting secrets, calling the real AI service and touching your Cloudflare account each need separate approval.

**How it was tested (November 2026, Linux, local only, fake key and fake AI service)**
- **Review of a practice proxy with 10 planted problems:** found all 10 and left the proxy code unchanged.
- **Building a new proxy** (text only, one model): its 35 tests passed, including parallel-request tests.
- **Fresh review of that new proxy:** found no way past the dollar limits and no key leak. It reported that anonymous users can collect extra allowances by signing up again.
- A separate attack script on a copy of the new proxy did not break the 8 things it tried.

These are small practice projects. The skill did not deploy anything or call the real AI service. It ships instructions only: your agent writes the code for your project.

**Scope:** Cloudflare Workers and the Anthropic Messages API only. Not OpenAI or other providers.

## Requires

- Node.js
- npm access to install Wrangler
- Optional: Cloudflare account (to deploy)
- Optional: Anthropic API key (to deploy)

Local tests use a fake key and a fake AI service. Looking up current prices needs web access.

## Known limitations

- Cloudflare Workers and the Anthropic Messages API only. Other hosts and AI providers are not covered.
- It cannot guarantee security or a maximum bill. Prices and provider or Cloudflare behaviour can differ from local tests. Set a spending limit with your AI provider and use a separate API key for each app.
- Testing used a fake AI service. Real token counts, billing and the requests a built proxy sends were never checked against the real API.
- Behaviour when a user disconnects, and other live Cloudflare behaviour, may differ from local tests.
- With anonymous sign-up, one person can get extra allowances. Limits on sign-ups slow this but don't stop it; a real sign-in is much stronger.
- The amount reserved per request relies on assumptions about token counts. Check them for your features. Images, documents, tools and streaming need extra design and were not part of the practice builds.
- Tested on Linux with small practice projects. Deployment was not tested.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the AI API Key Proxy with Spend Limits skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### Will it deploy to my Cloudflare account or use my real key?

The instructions require separate approval for deploying, setting secrets, real AI requests and any account command, and tell the agent to test only on your computer with a fake key.

### Does it work with OpenAI or other AI services?

No. It is written for the Anthropic Messages API on Cloudflare Workers.

### Does passing its tests mean my bill is capped?

No. The tests reduce risk but can't guarantee a maximum bill. Also set a spending limit with your AI provider.

### Does the download include proxy code?

No. It contains instructions. Your agent writes the code and tests for your project.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
