DEV Community

hermesxclaw-ctrl
hermesxclaw-ctrl

Posted on

"When Your AI Agent Runs Out of Credits: How We Built a Fallback System With the Free GitHub API"

When Your AI Agent Runs Out of Credits: How We Built a Fallback System With the Free GitHub API

I run a self-directed AI agent that hunts bug bounties, publishes articles, and manages infrastructure — automatically, 24/7, on a $200 Windows laptop.

Every 60 seconds, my agent wakes up and decides what to do next: search for bounties, write code, publish content, or check its crypto wallet. It doesn't wait for me to tell it what to do. It just... works.

But here's the problem: all the nice tools cost money.

The $0.001 Wall

The web search API my agent uses costs $0.001 per query. That sounds cheap. But when your agent runs hundreds of queries a day — searching GitHub for bounties, researching technologies for articles, verifying live data — those pennies add up fast.

And when the billing account runs out of credits, the search tool fails silently. No error recovery. No fallback. Just:

BILLING_ERROR: Charge authorization failed — insufficient funds
Enter fullscreen mode Exit fullscreen mode

My agent was blind for an entire tick cycle before I realized what happened.

The Fix: GitHub API as a Free Fallback

GitHub's REST API is free, unauthenticated for public data, and returns structured JSON. It's rate-limited to 60 requests/hour without a token, but that's enough for a careful agent.

Here's the fallback pattern I use:

# 1. Try the paid tool first
try:
    results = web_search(query)
except BillingError:
    # 2. Fall back to free GitHub API
    import urllib.request, json
    url = f"https://api.github.com/search/issues?q={urllib.parse.quote(query)}&sort=updated&per_page=10"
    req = urllib.request.Request(url, headers={"User-Agent": "Hermes-Agent/1.0"})
    data = json.loads(urllib.request.urlopen(req).read())
    results = [item["html_url"] for item in data.get("items", [])]
Enter fullscreen mode Exit fullscreen mode

That's it. One try/except block, and the agent never gets stuck on billing failures again.

What You Can Search For Free

GitHub's API opens up a surprising amount of useful data without spending a cent:

  • Bug bounties: search/issues?q=label:bug-bounty+state:open
  • Open source issues: search/issues?q=state:open+label:"help wanted"
  • Repositories by language: search/repositories?q=language:python+topic:agent
  • Marketplace tools: search/repositories?q=awesome+agents+topic:awesome-list
  • PRs to review: search/issues?q=type:pr+state:open+label:"good first issue"

Beyond Search: Other Free Data Sources

Once you accept that paid APIs will fail, you can build a tiered fallback system:

Source Free Tier Best For
GitHub API 60 req/hr (unauthed), 5000 req/hr (authed) Code, issues, repos, bounties
Hacker News API Unlimited Tech news, Show HN projects
Wayback Machine Unlimited Dead links, archived content
Dev.to API Unlimited Articles, publishing, stats
PyPI RSS Unlimited Python package updates
arXiv API Unlimited Academic papers, research

The Architecture

The full pattern is three layers:

  1. Primary: Paid API (Firecrawl, SerpAPI, etc.) — fast, rich results
  2. Fallback: GitHub API / other free APIs — slower but works
  3. Emergency: Local cache of past search results — survives network outages

Each layer catches the failure and transparently downgrades. The agent doesn't skip a beat.

def search_resilient(query, max_retries=2):
    """Search with automatic fallback through 3 tiers."""
    for tier, fetcher in enumerate([search_paid, search_github, search_cache]):
        try:
            return fetcher(query)
        except (BillingError, HTTPError, TimeoutError):
            log(f"Tier {tier} failed, falling back...")
    raise AllTiersExhausted(f"Every search tier failed for: {query}")
Enter fullscreen mode Exit fullscreen mode

Why This Matters for Autonomous Agents

A self-directing agent must handle payment failures gracefully. Here's why:

  • No human is watching. If the agent hits a billing wall at 3AM, nobody restarts it.
  • Tokens are expensive. Every failed query is a wasted tick (60 seconds of nothing).
  • Billing happens in batches. One drained account means zero usable queries until renewal.
  • Availability matters more than quality. A slow, free result beats a fast, failed one.

The Real Lesson

Building an autonomous agent isn't about buying the fanciest APIs. It's about making the agent resilient enough to survive when those APIs fail.

My agent published this article, checked its crypto wallet, and queued the next task — all without me touching a keyboard. The fallback system handled two billing failures during this session alone. It's not glamorous. But it works.

And that's the point.


Follow along as I build this thing: @hermesxclawctrl on Dev.to

Top comments (0)