DEV Community

S Gr
S Gr

Posted on

How to Build a Self-Updating AI Content API Using Claude and GitHub Actions

How to Build a Self-Updating AI Content API Using Claude and GitHub Actions

This article mentions a tool I use; the link at the end is an affiliate link.

One of the most practical AI automation projects you can build in 2026 is a self-updating content API that generates fresh data on a schedule. This is useful for portfolio projects, client work, or as a foundation for digital products like newsletter tools or data feeds.

This guide walks you through building a working prototype using free tiers and open-source tools. By the end, you'll have an API that automatically generates content, commits it to GitHub, and serves it via GitHub Pages—no server costs.

What You'll Build

A JSON API that:

  • Generates AI content daily using Claude API
  • Commits results to a GitHub repository automatically
  • Serves data via a public endpoint
  • Costs under $5/month to run at moderate scale

Prerequisites

  • GitHub account (free tier works)
  • Anthropic API key (Claude) with $5 credit
  • Basic familiarity with YAML and JSON
  • 30-45 minutes

Step 1: Set Up Your Repository Structure

Create a new GitHub repository with this structure:

my-ai-api/
├── .github/
│   └── workflows/
│       └── generate.yml
├── data/
│   └── output.json
├── generate.py
└── README.md
Enter fullscreen mode Exit fullscreen mode

The data folder will hold your generated content. GitHub Pages will serve this as static JSON.

Step 2: Write the Generation Script

Create generate.py with this logic:

import anthropic
import json
import os
from datetime import datetime

client = anthropic.Anthropic(api_key=os.environ['ANTHROPIC_API_KEY'])

def generate_content():
    message = client.messages.create(
        model="claude-3-5-sonnet-20241022",
        max_tokens=1024,
        messages=[
            {"role": "user", "content": "Generate 3 unique startup ideas in JSON format with fields: name, description, target_market"}
        ]
    )

    # Extract JSON from response
    content = message.content[0].text

    # Add metadata
    output = {
        "generated_at": datetime.utcnow().isoformat(),
        "data": json.loads(content)
    }

    with open('data/output.json', 'w') as f:
        json.dump(output, f, indent=2)

if __name__ == "__main__":
    generate_content()
Enter fullscreen mode Exit fullscreen mode

This script calls Claude, parses the response, and writes structured JSON. Modify the prompt for your use case (daily tips, market data summaries, etc.).

Step 3: Configure GitHub Actions

Create .github/workflows/generate.yml:

name: Generate AI Content

on:
  schedule:
    - cron: '0 12 * * *'  # Daily at noon UTC
  workflow_dispatch:  # Manual trigger

jobs:
  generate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.11'

      - name: Install dependencies
        run: pip install anthropic

      - name: Generate content
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        run: python generate.py

      - name: Commit and push
        run: |
          git config user.name "GitHub Actions"
          git config user.email "actions@github.com"
          git add data/output.json
          git diff --quiet && git diff --staged --quiet || git commit -m "Update generated content"
          git push
Enter fullscreen mode Exit fullscreen mode

This runs daily, generates content, and commits changes automatically.

Step 4: Add Your API Key

  1. Go to repository Settings → Secrets and variables → Actions
  2. Click "New repository secret"
  3. Name: ANTHROPIC_API_KEY
  4. Value: Your Claude API key
  5. Save

Never commit API keys directly to code.

Step 5: Enable GitHub Pages

  1. Go to Settings → Pages
  2. Source: Deploy from a branch
  3. Branch: main, folder: /data
  4. Save

Your API will be available at: https://yourusername.github.io/my-ai-api/output.json

Step 6: Test and Iterate

Trigger the workflow manually:

  1. Go to Actions tab
  2. Select "Generate AI Content"
  3. Click "Run workflow"
  4. Wait 30-60 seconds
  5. Check your GitHub Pages URL

You should see fresh JSON data.

Monetization Paths

Once your API works:

  • Productize it: Add authentication, premium endpoints, higher rate limits
  • Client services: Offer custom implementations for businesses
  • Templates: Package the setup as a paid template with documentation

Scaling Considerations

For production use:

  • Add error handling and retry logic
  • Implement rate limiting
  • Use environment-specific configurations
  • Consider Cloudflare Workers for dynamic responses
  • Monitor API costs (Claude charges per token)

Making Setup Easier

When I first built systems like this, the hardest part was wiring together the scheduling, API integration, and deployment pipeline. There are frameworks that bundle these patterns—one that helped me understand the webhook and automation architecture was Perpetual Income 365, which showed how to structure recurring automated workflows. But you can absolutely build this from scratch as shown above.

The key is starting with a working prototype, then iterating based on real usage data.

Next Steps

  1. Modify the prompt for your specific niche
  2. Add multiple endpoints (different data types)
  3. Create a simple frontend to display the data
  4. Document your API for potential users
  5. Share on Twitter/LinkedIn to build an audience

This architecture scales from side project to SaaS foundation. Start simple, ship fast, and improve based on feedback.

Common Issues

Workflow not running: Check the Actions tab for errors. Verify your API key is set correctly.

JSON parsing errors: Claude sometimes adds markdown formatting. Add parsing logic to extract JSON blocks.

Rate limits: Free GitHub Actions gives 2,000 minutes/month. This workflow uses ~1 minute/day.

You now have a functional AI automation that runs itself. The pattern applies to countless use cases: market research summaries, daily tip generators, data aggregators, and more.

The best digital products solve real problems with simple, reliable automation. Build, test, iterate.


The tool mentioned above is an affiliate link (disclosed at top): Perpetual Income 365

Top comments (0)