DEV Community

Taylor Lin
Taylor Lin

Posted on

Free Tokens + Free Server: A Decision Tree for Zero-Cost AI Scripts

You wrote a script that pulls a GitHub issue, asks an AI model to summarize it, and posts the summary to Slack. It works on your laptop. Now your laptop is closed, and the issue is still open. Where does the script run? You could pay for a VPS, but you remember there are free servers. You could pay for model calls, but someone said a free token allowance exists. The problem isn't code anymore. It's choosing where to host a budget of zero.

This article is a glossary plus a decision tree for that exact problem. At the end you'll have a reproducible path for running AI-powered scripts on free resources — with one honest caveat: free tier means free-tier constraints.

Glossary: Terms a Balanced Budget Requires

Before the branches, know the vocabulary. Free tiers are usually limited by these terms:

  • Free model API: An HTTP endpoint that lets you send prompts and get completions without paying. Limits are real: tokens per minute, requests per day, or total tokens per month.
  • Token: A chunk of text the model processes. 1 token ≈ 4 English characters. Every request counts your input and output tokens against the quota.
  • Rate limit: How many requests you can fire per second/minute. Exceeding it returns 429 status codes. Your script needs retries.
  • Cold start: The delay when an idle serverless function or free server spins up after sleeping. Free servers often sleep after 5-30 minutes of no traffic.
  • Always-on server: A machine that runs your process continuously (or wakes on schedule) with a public IP or domain. Free tiers cap storage, RAM, and CPU.
  • Cron job: A scheduled task on Unix systems. Good for recurring batch work — but only if the machine is awake at the scheduled time.
  • Webhook: An HTTP callback triggered by an event (e.g., a new GitHub issue). Your server must be reachable, or the event goes nowhere.

Now we can ask the questions that matter.

The Decision Tree

I like decision trees because they force you to admit constraints before touching code. Here's a minimal one for any AI script on a $0 budget:

Does your script need a public endpoint?
├── No
│   ├── Does it need to run on a schedule?
│   │   ├── Yes → Leaf 1: Local cron + free model API
│   │   └── No  → Leaf 2: Local one-off run + free model API
└── Yes
    ├── Can you tolerate cold starts?
    │   ├── Yes → Leaf 3: Serverless function + free model API
    │   └── No  → Leaf 4: Free always-on server + free model API
Enter fullscreen mode Exit fullscreen mode

Each leaf has a worked example. Let's walk them.

Leaf 1: Local cron + free model API

Your script runs every midnight, needs no inbound traffic, and your laptop stays on. Create a crontab entry:

0 0 * * * /usr/bin/python3 /home/user/scripts/digest.py
Enter fullscreen mode Exit fullscreen mode

Add retry logic inside digest.py for rate limits:

import time
import requests

def call_model(prompt):
    for attempt in range(3):
        resp = requests.post(
            "https://free-model.example/v1/chat",
            json={"prompt": prompt},
            timeout=30,
        )
        if resp.status_code == 429:
            time.sleep(2 ** attempt)
            continue
        return resp.json()
Enter fullscreen mode Exit fullscreen mode

Pros: Full control, no cold start, free. Cons: laptop off = job skipped.

Leaf 2: Local one-off run + free model API

You have a manual task: classify a CSV or summarize a README. Just run it when needed.

python classify.py input.csv --output classified.csv
Enter fullscreen mode Exit fullscreen mode

Track token usage with a simple counter — free quotas evaporate fast on big files.

Leaf 3: Serverless function + free model API

You need a public URL, and a 10-second cold start is fine. Use a cloud provider's free serverless tier. The code becomes an HTTP handler:

def handle(event):
    text = event["queryStringParameters"]["text"]
    summary = call_model(f"Summarize: {text}")
    return {"statusCode": 200, "body": summary}
Enter fullscreen mode Exit fullscreen mode

Cons: Some free serverless tiers allow very short execution times (10-60s). Long AI calls may time out.

Leaf 4: Free always-on server + free model API

You need a warm public endpoint or a reliable cron job. Here, a free always-on server wins. You get a small VM with a public IP, limited disk (often 5-10GB), and a sleep policy — but as long as something pings it, it stays awake.

A simple setup: install Python, run a Flask app, and add a cron job. Let's make this leaf concrete.

A Worked Leaf: Free Server + Free Model API

Imagine a bot that watches a GitHub repo's issues and posts summaries to a webhook. On a free always-on server:

Step 1 — Start a minimal HTTP server (keeps the server awake and exposes a health check):

from flask import Flask, jsonify
app = Flask(__name__)

@app.route("/health")
def health():
    return jsonify({"ok": True})
Enter fullscreen mode Exit fullscreen mode

Step 2 — Write the model call with retry and token caps:

import os, requests, time

MODEL_URL = os.environ["MODEL_URL"]
API_KEY = os.environ["API_KEY"]

def summarize_issue(title, body):
    prompt = f"Summarize this GitHub issue in 3 bullets:\n{title}\n{body[:1500]}"
    for attempt in range(4):
        r = requests.post(
            MODEL_URL,
            headers={"Authorization": f"Bearer {API_KEY}"},
            json={"prompt": prompt, "max_tokens": 150},
            timeout=30,
        )
        if r.status_code == 429:
            time.sleep(2 ** attempt)
            continue
        return r.json()["text"]
    return "Skipped: rate-limited"
Enter fullscreen mode Exit fullscreen mode

Step 3 — Schedule it with cron (inside the server):

*/30 * * * * cd /home/user/bot && python check_issues.py >> logs/bot.log 2>&1
Enter fullscreen mode Exit fullscreen mode

Step 4 — Check free-tier limits. Your script uses tokens every 30 minutes. A 150-token output per run is about 7,200 tokens a day. That fits a modest free allowance — but only if you actually read the quota docs.

That's the whole pattern. Now, where do you get both a free model API and a free always-on server in one place?

Where MonkeyCode Fits

One open-source project that bundles both is MonkeyCode. It offers a free model API tier with a token allowance and a free always-on server option for small scripts like this. That makes Leaf 4 much easier to test without stitching together three different free accounts.

Disclosure: This article was prepared as part of MonkeyCode's product outreach.

I used this exact pattern to run a small issue-summarizer test. The server stayed responsive, and the model responded within normal latency for a free tier. No magic, just a familiar stack: Python, a cron job, and one API call.

Should you trust it for production? Read the next section first.

Limitations and Boundary Cases

Free tiers are not a replacement for paid infrastructure. Here are the boundaries I hit or expect:

  • Sleep — Free always-on servers often sleep after inactivity. Keep a /health endpoint and hit it every five minutes from an external cron, or accept a few seconds' delay.
  • Storage — Small disk means log rotation is mandatory. Use logrotate or pin your bot's log directory with a cleanup cron:
  0 3 * * * find /home/user/bot/logs -mtime +7 -delete
Enter fullscreen mode Exit fullscreen mode
  • Rate limits — Your model API may return 429 during your own test spike. Always include exponential backoff.
  • Token budget — Without monitoring, you'll burn a month's quota in one afternoon. Wrap every request in a counter that logs cumulative tokens.
  • No SLA — If the script stops, no one is paged. This is fine for personal dashboards; it's not fine for billing or incident response.

Who Should Skip This

Don't use this approach if you need: guaranteed uptime, sub-second responses, processing sensitive data, or a team-wide dependency on a free API. Also skip it if your workload is genuinely massive (e.g., summarizing millions of records). In those cases, pay for a small VM and a real model endpoint — the cost is lower than the debugging time you'll otherwise spend.

When it works, though, it's lovely: a zero-budget script that runs while you sleep, on a server you never had to lease.

The One Thing to Take Away

Decision trees don't replace reading the docs. They shorten the path to your first working deployment. Pick your leaf, read the quota page, set up health checks, and log everything.

If you want a sandbox to try this exact setup, MonkeyCode's free tier is a reasonable place to start — just treat its limits as research, not a guarantee.

Now go move that script off your laptop.

Top comments (0)