Acquire a concurrency lock without proxying

Goal

Share the same source's concurrency limit and keys as proxy traffic, but perform the upstream HTTP call from your own process. Typical cases: a connector that cannot rewrite the base URL, or a worker that must keep the origin client library as-is.

Full request and response shapes live in the Concurrency locks API.

Pattern

  1. Acquire a slot on https://api.swarmvia.cloud (not the source's endpoint).
  2. Call the upstream yourself while holding the slot.
  3. Renew about every 10 seconds if the work can exceed one lease term.
  4. Release when finished. Include throttle fields if the upstream returned 429 so adaptive / RPM control can learn.
export ACCESS_KEY='sv_at_…'
export LOCK_API='https://api.swarmvia.cloud/pools/your-source/lock'

# Fail fast when the source is full; add "waitMs" to join the queue.
GRANT=$(curl -sS -X POST "$LOCK_API/acquire" \
  -H "X-Swarmvia-Key: $ACCESS_KEY" \
  -H "Content-Type: application/json")
SLOT_ID=$(printf '%s' "$GRANT" | jq -r .slotId)

# … your upstream call …

curl -sS -X POST "$LOCK_API/$SLOT_ID/release" \
  -H "X-Swarmvia-Key: $ACCESS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"status":200}'

Auth and credentials

Use the same access key (and optional JWT / Cloudflare Access) as the proxy. Access keys expire, and renew and release check the key, so hold one that outlives the slot. A long-running worker mints fresh keys with a Control API token; see Refresh access tokens before they expire. The lock API never emits managed upstream credentials. On a managed source you still supply origin auth yourself when you call the upstream.

See also