tools / photon

Multi-provider orchestration at the edge.

Photon is the origin story: one Cloudflare Worker fronting isolated, hibernating containers per AI provider (Claude, OpenRouter's 75+ models, and more), with authentication, rate limiting, per-account billing, and full audit logging to R2. The heavier, container-based foundation that led to Pacifico.

Cloudflare Workers + Containers Self-hosted v1.0.0 Open source

The problem

Running agents across multiple AI providers means juggling credentials, managing provider-specific client libraries, and handling each one's rate limits and failures independently. Add cost tracking and audit requirements, and the operational surface explodes.

What Photon does

Photon provides one authenticated gateway to every AI provider. Send a request specifying a model (Claude, GPT-4, OpenRouter's Llama, Cohere, Mistral, anything OpenRouter supports — 75+ models), and Photon routes it to the right isolated container. Each provider runs in its own sandbox: containers spin up on demand and hibernate when idle, spinning down unused instances automatically to cut costs.

Authentication is unified: API keys per provider are stored and managed in Cloudflare. Agents authenticate once to Photon with their credentials. Rate limiting, retry logic, and circuit breakers work uniformly across all providers. Cost is tracked per account with a credit system — debit tokens, replenish via Stripe, never overrun your budget.

Every request is logged and stored immutably in R2: what model ran, what the input and output were, how long it took, and what it cost. Audit compliance baked in.

What makes it different

  • Isolated containers per provider. Not a shared runtime with provider-specific code paths. Each provider (Claude, OpenRouter, Synthetic, Mako orchestration) runs in its own lightweight container — failures are isolated, resource contention is eliminated, and it's easy to add new providers without touching the Worker.
  • Hibernating containers. Containers sleep when idle and wake on demand. You pay only for active time. A fleet of agents with variable usage patterns keeps cost proportional to actual use, not peak capacity.
  • Cost control is a first-class feature. Credits, billing events, rate limiting — not add-ons but core plumbing. Agents can't spend beyond their allocation, period.
  • The origin of cost-aware routing. Photon proved the concept: expensive calls should be isolated, batched, and managed differently. That insight became the design center for Pacifico, which distilled the same ideas into a leaner single-Worker approach.

Deploy

Clone and deploy to your own Cloudflare account:

git clone https://github.com/ruizrica/photon-agents
cd photon-agents
cp .dev.vars.example .dev.vars
# Configure your API keys in .dev.vars
wrangler deploy

Photon requires Docker to run containers on Cloudflare. Configuration happens in .dev.vars: your provider API keys, D1 database credentials for billing, R2 bucket for audit logs, and Stripe webhook keys if you want billing integration. Once deployed, all inference runs through your Photon instance in your Cloudflare account.

Photon builds on the open-source claude-agent-sdk-cloudflare project. This implementation extends that foundation with multi-provider support, container orchestration, and billing.