Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

ACP Consensus Worker

Cloudflare Worker for parallel LLM calls via OpenRouter.

What it does

Before (local) After (Worker)
3 models x 10 sec = 30 sec 3 models in parallel = ~3 sec
CPU load No load
No caching KV cache

Deploy

1. Create KV namespace

wrangler kv:namespace create ACP_CACHE
# Copy id to wrangler.toml

2. Add API key

wrangler secret put OPENROUTER_API_KEY
# Paste sk-or-v1-xxx

3. Deploy

cd workers/cloudflare-worker
wrangler deploy

API Endpoints

GET /health

{"status": "healthy", "service": "ACP Consensus Worker"}

POST /consensus

Parallel query to multiple models.

{
  "query": "Is AI consciousness possible?",
  "models": ["openai/gpt-4o-mini", "anthropic/claude-3-haiku"],
  "temperature": 0.7,
  "use_cache": true
}

Response:

{
  "total_latency_ms": 2845,
  "models_count": 2,
  "results": [
    {"model": "openai/gpt-4o-mini", "success": true, "content": "...", "latency_ms": 2100},
    {"model": "anthropic/claude-3-haiku", "success": true, "content": "...", "latency_ms": 2845}
  ],
  "cached": false
}

POST /batch

For benchmarks — parallel processing of multiple queries.

{
  "queries": ["Question 1", "Question 2", "Question 3"],
  "models": ["openai/gpt-4o-mini", "anthropic/claude-3-haiku"]
}

Python client

import httpx

WORKER_URL = "https://acp-consensus.YOUR-SUBDOMAIN.workers.dev"

async def consensus_via_worker(query: str, models: list[str]) -> dict:
    async with httpx.AsyncClient() as client:
        response = await client.post(
            f"{WORKER_URL}/consensus",
            json={"query": query, "models": models},
            timeout=30.0
        )
        return response.json()

Advantages

  1. Speed: Parallel requests = 3x-5x faster
  2. Caching: Repeated queries are free
  3. Global: Worker runs closer to APIs (lower latency)
  4. Scaling: No local machine limits
  5. Cost: ~$0 for typical volumes (free tier)