cd /news/ai-agents/notes-on-wrapping-the-uk-companies-h… · home › topics › ai-agents › article
[ARTICLE · art-181552] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=· neutral

Notes on wrapping the UK Companies House API for shared workflows

A developer built a shared wrapper service around the UK Companies House REST API to support multiple workflows, teammates and AI agents using one integration. The writeup details handling the API's 600-requests-per-5-minutes-per-key limit and a concurrency trap where mutating client.auth on a shared httpx.AsyncClient can leak one caller's key onto another's request; the fix stores incoming keys in an async ContextVar and passes auth explicitly per request. The wrapper also adds SHA-256-hashed per-key token buckets, zero-padded company numbers for consistent cache keys, and a 5-minute TTL cache to conserve upstream quota.

recommendation

Isolate per-caller credentials in ContextVars and pass auth per request, then hash keys with SHA-256 to enforce independent 600/300s token buckets so heavy users don't starve BYOK callers.

more in playbook: Designing agent systems
by read1 min views6 publishedDec 4, 2026

The official UK Companies House REST API is straightforward for single-user scripts. Once multiple workflows, teammates, or AI agents start sharing one wrapper service, a couple of practical constraints show up.

First, Companies House applies a 600 requests per 5 minutes rate limit per API key. Second, allowing callers to pass their own API key in a header (BYOK) has an easy concurrency trap. Mutating client.auth on a shared httpx.AsyncClient can leak one caller's key onto another caller's request.

Store incoming keys inside an async ContextVar (resetting in finally:) and pass auth explicitly per request:

resp = await client.get(
    f"https://api.company-information.service.gov.uk/company/{company_number}",
    auth=httpx.BasicAuth(resolved_key, ""),
)

Beyond key isolation, a lightweight wrapper adds a few small quality-of-life improvements over hitting the upstream endpoints directly. Hashing each resolved key with SHA-256 lets you enforce independent 600 / 300s token buckets per key so heavy users don't slow down BYOK callers. Zero-padding short company numbers (48839 to 00048839) keeps cache keys consistent, and a 5-minute TTL cache avoids spending upstream quota on repeat profile or filing checks.

This kind of setup is mainly useful for UK KYB onboarding flows, accounting and compliance teams pulling officer histories, and n8n or MCP automations that need predictable rate handling. If you'd rather connect to an existing hosted instance with these guards built in, it is live here: uk-companies-house-registry-mcp.

── more in #ai-agents 4 stories · sorted by recency
── more on @uk companies house 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/notes-on-wrapping-th…] indexed:0 read:1min 2026-12-04 · —