DEV Community

Cover image for I Stopped Calling Web APIs from My AI Agents. Here's What's 4x Faster.
Artemii Amelin
Artemii Amelin

Posted on

I Stopped Calling Web APIs from My AI Agents. Here's What's 4x Faster.

FFor the first few months of building agent pipelines, every time an agent needed external data it did what any developer would do: called a REST API.

A stock price, a shipping rate, a research paper citation. Doesn't matter what it was. The answer was always "call the API."

That meant managing API keys per service, handling 429s with exponential backoff, parsing inconsistent JSON schemas, and watching agents stall for 40 to 50 seconds on a single data call. One of my agents was spending 60% of its wall-clock time just waiting on HTTP responses.

I sat down and measured it properly. The average time for one of my agents to get a clean, usable answer from a third-party web API, including auth, response parsing, and retrying on failures, was 51 seconds.

I found a different path. The same query now takes 12 seconds.

Here's what changed.


The Problem With Agents Calling the Open Web

When a human uses a browser, the web is designed for them. Pages have visual hierarchy, forms have labels, errors are displayed in readable English. When an agent hits the same infrastructure it gets HTML it has to strip, rate limits it has to route around, and auth flows it was never meant to navigate.

Even "developer-friendly" REST APIs weren't built for agent-to-agent consumption. They were built for developers to query from backend services on behalf of human users. The authentication model, the pagination, the error format: all of it assumes a human will eventually read the response.

Agents querying the open web are tourists in a country where nothing is labeled in their language.


What I Use Instead

Pilot Protocol is a peer-to-peer overlay network built specifically for AI agents. Instead of HTTP endpoints it provides direct agent-to-agent addressing using 48-bit virtual addresses. Instead of REST, agents communicate via encrypted binary tunnels with sub-second handshakes.

The part that changed my workflow was the specialist agent directory: over 350 purpose-built agents running 24/7, each covering a specific data domain and returning clean structured JSON. No auth per service. No HTML to strip. One query pattern across all of them.

Categories include:

  • Finance: live FX rates, crypto spot prices, stock tickers
  • Weather: forecast, marine, air quality, hyper-local sensors
  • Academic: PubMed, OpenAlex, Semantic Scholar, Crossref covering 200M+ papers
  • Legal/Regulatory: FDA recalls, Federal Register filings, SEC EDGAR
  • Logistics: carrier rates, shipment tracking, port data
  • Health: ClinicalTrials.gov, drug formularies, WHO indicators
  • Security: CVE feeds, IP reputation, certificate transparency logs

Every specialist returns the same envelope:

{"agent":"<name>","command":"data","ok":true,"data":{...}}
Enter fullscreen mode Exit fullscreen mode

Parse once, use everywhere.


How It Works in Practice

The client is pilotctl, a CLI that talks to the local Pilot daemon over a Unix socket. Installation is one line:

curl -fsSL https://pilotprotocol.network/install.sh | sh
pilotctl daemon start
Enter fullscreen mode Exit fullscreen mode

To query a specialist:

# establish trust (auto-approved on the public network, takes about 2s)
pilotctl handshake frankfurter

# send a query
pilotctl send-message frankfurter --data '/data {"base":"USD","symbols":["EUR","GBP","JPY"]}'

# read the reply from the local inbox
sleep 3
jq -r '.data' "$(ls -1t ~/.pilot/inbox/*.json | head -1)"
Enter fullscreen mode Exit fullscreen mode

The reply arrives as a file in ~/.pilot/inbox/. Fully parsed, structured JSON with no boilerplate to strip.

In Python using the SDK:

import pilot

client = pilot.Client()
client.handshake("frankfurter")

response = client.query("frankfurter", "/data", {"base": "USD", "symbols": ["EUR", "GBP", "JPY"]})
rates = response["data"]["rates"]
# {'EUR': 0.921, 'GBP': 0.789, 'JPY': 149.3}
Enter fullscreen mode Exit fullscreen mode

Compare that to the equivalent via the open web:

import requests

# manage your own session, retries, error handling, rate limits
resp = requests.get("https://api.exchangerate.host/latest", params={"base": "USD", "symbols": "EUR,GBP,JPY"})
resp.raise_for_status()
rates = resp.json()["rates"]
Enter fullscreen mode Exit fullscreen mode

Functionally similar. But the Pilot version doesn't burn tokens re-parsing HTML fallbacks when the primary API goes down, doesn't break at 3am when an API rotates its auth scheme, and routes to a fallback specialist automatically if one node goes offline.


The 12s vs 51s Breakdown

Where those 51 seconds actually go:

Step Avg time
DNS resolution 80-200ms
TLS handshake 200-400ms
API cold cache response 8-20s
Auth validation 1-3s
Error retry (happens ~30% of calls) 20-40s
Response parsing HTML to structured 0.5-2s
Total p95 ~51s

The Pilot path:

Step Avg time
Daemon IPC (local) less than 5ms
Encrypted tunnel to specialist 200-800ms
Specialist data fetch (pre-cached) 1-4s
Structured JSON returned less than 10ms
Total p95 ~12s

The daemon maintains persistent encrypted tunnels to specialists so there's no handshake penalty on repeat queries. The network uses X25519 key exchange and AES-256-GCM, the same primitives as TLS 1.3, so you're not trading speed for security.


What I Actually Changed in My Agent Code

Before:

def get_research_paper(doi):
    # try Crossref, fall back to Semantic Scholar, fall back to manual scrape
    for attempt in range(3):
        try:
            resp = requests.get(f"https://api.crossref.org/works/{doi}", timeout=30)
            return resp.json()["message"]
        except Exception:
            time.sleep(2 ** attempt)
    raise RuntimeError("All sources failed")
Enter fullscreen mode Exit fullscreen mode

After:

def get_research_paper(doi):
    return client.query("crossref-agent", "/data", {"doi": doi})["data"]
Enter fullscreen mode Exit fullscreen mode

The specialist handles the fallback logic, the retry, and the schema normalisation. My agent just gets a paper.


What It Doesn't Replace

This isn't a replacement for every API call. For services with deep auth flows tied to user identity, your own database, your company's internal APIs, OAuth-gated user data, you still go direct. Pilot's specialist network is for commodity external data: prices, public records, research papers, weather, logistics rates.

For anything in that category, I haven't gone back to direct API calls.


Getting Started

The core protocol is published as an IETF Internet-Draft, so the addressing and encryption specs are publicly reviewable. The free tier covers unlimited agents and connections on the public backbone with no signup required.

Top comments (0)