Skip to main content

Serverless AI inference via GitHub Actions — no server required

Project description

gh-ai-runner

PyPI version License: MIT Python 3.9+

Serverless AI inference via GitHub Actions. No server. No GPU. No infrastructure.

Run open-source LLMs directly through GitHub's free CI/CD runners — just a GitHub token and a prompt. gh-ai-runner handles everything else: repo creation, workflow setup, model downloading, caching, and output retrieval.

Built by Tanish Chauhan


How it works

When you call ai_call():

  1. Creates a private GitHub repo (once, automatically)
  2. Commits a workflow + inference script into it
  3. Dispatches a workflow_dispatch GitHub Actions run
  4. The runner downloads and caches the model (GGUF quantized, ~0.6 GB)
  5. Runs inference via llama-cpp-python
  6. Uploads the output as an artifact
  7. Downloads and returns the output to you as a string

No server is ever running between calls. Each call spins up a fresh GitHub Actions runner, runs inference, and shuts down.


Install

pip install gh-ai-runner==0.1.3

Requirements:

  • Python 3.9+
  • A GitHub account with a personal access token (PAT)
  • Token scopes needed: repo, workflow

Quickstart

from gh_ai_runner import ai_call

result = ai_call(
    github_token="ghp_...",
    prompt="explain recursion in simple terms",
)

print(result)

That's it. On first run, gh-ai-runner will:

  • Create a repo called ai-inference-runner on your GitHub account
  • Set up the workflow automatically
  • Download and cache TinyLlama 1.1B (~0.6 GB)

Subsequent calls reuse the cached repo and model.


Examples

Basic question

from gh_ai_runner import ai_call

result = ai_call(
    github_token="ghp_...",
    prompt="what is the difference between a list and a tuple in Python?",
)
print(result)

Custom system prompt

result = ai_call(
    github_token="ghp_...",
    prompt="explain black holes",
    system="You are a physics professor. Be precise and use analogies.",
    model="llama",
    max_tokens=1024,
)
print(result)

Deterministic output (temperature=0)

result = ai_call(
    github_token="ghp_...",
    prompt="what is 144 divided by 12?",
    temperature=0.0,
    max_tokens=16,
)
print(result)  # always returns the same answer

Silent mode (no logs)

result = ai_call(
    github_token="ghp_...",
    prompt="summarize the theory of evolution",
    verbose=False,
)
print(result)

Large output

result = ai_call(
    github_token="ghp_...",
    prompt="write a detailed essay on the causes of World War I",
    max_tokens=2048,
    temperature=0.5,
    model="llama",
)
print(result)

Multiple calls in sequence

from gh_ai_runner import ai_call

TOKEN = "ghp_..."

questions = [
    "what is a neural network?",
    "what is gradient descent?",
    "what is backpropagation?",
]

for q in questions:
    answer = ai_call(github_token=TOKEN, prompt=q, verbose=False)
    print(f"Q: {q}\nA: {answer}\n")

Parallel calls (use separate repo per call)

import threading
from gh_ai_runner import ai_call

TOKEN = "ghp_..."
results = {}

def run(key, prompt, repo):
    results[key] = ai_call(
        github_token=TOKEN,
        prompt=prompt,
        repo_name=repo,
        verbose=False,
    )

t1 = threading.Thread(target=run, args=("q1", "explain DNA", "runner-repo-1"))
t2 = threading.Thread(target=run, args=("q2", "explain RNA", "runner-repo-2"))

t1.start(); t2.start()
t1.join();  t2.join()

print(results["q1"])
print(results["q2"])

Note: Parallel calls must use different repo_name values. Each repo has its own independent run queue, so calls never interfere with each other.


Parameters

Parameter Type Default Required Description
github_token str Yes GitHub PAT with repo and workflow scopes
prompt str Yes The message or question to send to the model
model str "tinyllama" No Which model to use. See Models section below
system str "You are a helpful assistant." No System prompt that controls model behavior
max_tokens int 512 No Max tokens to generate. Hard limit: 4096
temperature float 0.7 No Randomness. 0.0 = deterministic, 2.0 = very creative
cache bool True No Cache model weights between runs. Strongly recommended
n_ctx int None No Context window size. Defaults to model built-in. Max: 8192
repo_name str "ai-inference-runner" No GitHub repo to create or reuse for running inference
verbose bool True No Print step-by-step logs. Set False for silent mode

Models

Key Model Size Default Context Max Safe Context
tinyllama TinyLlama 1.1B Chat Q4_K_M 0.6 GB 2048 tokens 8192 tokens
llama Llama 3.2 1B Instruct Q4_K_M 0.7 GB 4096 tokens 8192 tokens

Both models are quantized GGUF files hosted publicly on HuggingFace. No HuggingFace token required.

Which model should I use?

  • tinyllama — faster, smaller, good for short factual answers and simple tasks
  • llama — better instruction-following, better for longer structured outputs and reasoning

Context and output size

The context window (n_ctx) is the total number of tokens the model can see at once — this includes your system prompt, your prompt, and the generated output combined.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gh_ai_runner-0.1.4.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gh_ai_runner-0.1.4-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file gh_ai_runner-0.1.4.tar.gz.

File metadata

  • Download URL: gh_ai_runner-0.1.4.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for gh_ai_runner-0.1.4.tar.gz
Algorithm Hash digest
SHA256 9eff43343a8820d473761e2769c82fca501dfcdcd0d5c83f66d530fecc512c6d
MD5 6f8460a5e6137e055ba2da5e5d9896e1
BLAKE2b-256 8c38396b7c68b3185729ef7f6cbb0713f3f593811474bd2071b1289751f3f7ab

See more details on using hashes here.

File details

Details for the file gh_ai_runner-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: gh_ai_runner-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for gh_ai_runner-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c13c537f5dfccecb1aaecaf8ab96f0da05e8166365f1ebd6cf07c5e038136312
MD5 eebbbc331637f82956489f9b2de7df19
BLAKE2b-256 1aa040a191b29be3a850501c04a9bb385298cef8009ebcf39304ea30d1b6fc5e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page