tools / pacifico

Cost-aware AI at the edge.

Pacifico is a single Cloudflare Worker that intelligently routes each prompt: cheap models run synchronous, expensive models queue for batch APIs (~50% savings), all authenticated and logged. Plugs into Claude Code as an MCP server.

Cloudflare Workers Self-hosted v0.1.0 MCP-native

The problem

Running intelligent agents means calling expensive models frequently. Claude Opus, GPT-5, and other reasoning models cost 10–100x more per token than smaller models. Yet every prompt waits synchronously for a response, forcing expensive calls even when they could defer safely. The bill compounds: a fleet of agents generating dozens of prompts per session multiplies cost instantly.

What Pacifico does

Pacifico is a cost router with one hard rule: expensive models never run realtime. Each prompt is classified by estimated cost. Cheap requests (small models, simple tasks) execute synchronously through Cloudflare's AI Gateway. Expensive requests (Opus, GPT-5.5, reasoning tasks) queue onto Cloudflare Queues and batch into Anthropic or OpenAI Batch APIs, which run overnight and return results at ~50% of realtime pricing. Context-compression Service Agents shrink large contexts before expensive calls ship out, cutting both cost and latency.

Three-tier authentication lets you scale: Google OAuth for interactive users, PKCE tokens for CLI agents, scoped hashed keys for integrations. Every request audits to your own Cloudflare account.

What makes it different

  • Batch is the default for expensive work. Other gateways treat batch as an afterthought. Pacifico forces it: if a model would cost more than a threshold, it queues automatically. No configuration, no per-request decision.
  • MCP server native. Not a REST API requiring boilerplate. Pacifico registers itself to Claude Code as an MCP server in one command: pacifico install wires it into ~/.claude/mcp.json. Claude Code agents call Pacifico as a first-class tool.
  • Everything runs in your Cloudflare account. No middle-ground SaaS. Clone the repo, configure your API keys, deploy once — all your traffic, all your logs, all your spend stays in your own infrastructure.
  • 9 architecture decision records. Routing logic, cost classification, auth design — every choice is documented for agents to understand and extend.

Deploy

Clone the repository and deploy to your own Cloudflare account:

git clone https://github.com/ruizrica/pacifico
cd pacifico
wrangler deploy

Configuration happens via environment variables in your Cloudflare Worker secret store: your Anthropic API key, OpenAI key, Google OAuth credentials, and billing thresholds. Once deployed, Pacifico runs entirely in your Cloudflare account — your Workers, your Queues, your D1 database, your audit logs in R2.