DEV Community

Cover image for Build an AI-Powered SEO Content Brief Generator with Python and SERP API
LEO o
LEO o

Posted on

Build an AI-Powered SEO Content Brief Generator with Python and SERP API

Ever spent hours researching what to write for your next blog post? You have to manually check the top 10 results, analyze what's working, and figure out how to make something better. What if you could automate that entire process with a few lines of code?
Today, we're going to build an AI-powered SEO content brief generator that automatically pulls the top 10 search results for your keyword and uses GPT to create a complete content brief. It takes about 10 minutes, and we'll be using Python and SERP API from Talordata.

Why Automate This?

Creating a good content brief used to take me 30-60 minutes per keyword. I'd:
Open incognito mode and search Google
Manually copy/paste titles and summaries into a document
Read through everything to identify common themes
Outline a structure that could compete
That's a lot of repetitive work that a computer can do for us. With automation, I can generate a complete content brief in under 10 seconds, and I just focus on writing the actual content.

Why Use a SERP API Instead of Scraping?

I tried building my own scraper for this years ago, and it was a never-ending maintenance nightmare:
Google keeps changing their HTML structure, so my selectors would break every few months
I kept getting blocked and had to mess around with rotating proxies
CAPTCHAs would randomly stop everything
When Google loads content dynamically with JavaScript, I needed a whole headless browser
Using a SERP API means someone else handles all that for you. You just make one API call and get clean structured JSON back.
I'm using TalorData for this project because:
1,000 free requests on signup (no credit card required)
$1.00 per 1,000 requests — super affordable
Simple API that doesn't require a heavy SDK
Supports Google, Bing, and Yandex out of the box

Let's Code It!

Install dependencies:

bash
pip install requests openai python-dotenv

Enter fullscreen mode Exit fullscreen mode

Create a .env file:

TALORDATA_TOKEN=your_talordata_token_here
OPENAI_API_KEY=your_openai_key_here

Enter fullscreen mode Exit fullscreen mode

Complete code:

import requests
import openai
import os
from dotenv import load_dotenv

load_dotenv()
TALORDATA_TOKEN = os.getenv("TALORDATA_TOKEN")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
openai.api_key = OPENAI_API_KEY

def get_top_results(keyword: str, engine: str = "google", limit: int = 10):
    """Fetch top N search results from SERP API"""
    url = "https://serpapi.talordata.net/serp/v1/request"

    headers = {
        "Authorization": f"Bearer {TALORDATA_TOKEN}",
        "Content-Type": "application/x-www-form-urlencoded"
    }

    data = {
        "engine": engine,
        "q": keyword,
        "json": "2"
    }

    response = requests.post(url, headers=headers, data=data)
    response.raise_for_status()
    results = response.json()

    return [
        {
            "position": r["position"],
            "title": r["title"],
            "snippet": r.get("snippet", "")
        } 
        for r in results.get("organic_results", [])[:limit]
    ]

def format_results_for_prompt(results):
    """Format search results into something the LLM can read"""
    output = "Current top 10 search results:\n\n"
    for i, result in enumerate(results, 1):
        output += f"#{i} - Title: {result['title']}\n"
        output += f"Summary: {result['snippet']}\n\n"
    return output

def generate_content_brief(keyword: str, results):
    """Generate content brief using GPT"""
    context = format_results_for_prompt(results)

    prompt = f"""
You are an SEO expert. I want to write an article targeting: "{keyword}"

Based on the current top 10 search results below, create a detailed content brief:

1. What common themes do all the top articles cover?
2. What title patterns work well?
3. What content gaps exist?
4. A suggested article structure
5. Tips to stand out from competition

{context}
"""

    response = openai.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": prompt}],
        temperature=0.7
    )

    return response.choices[0].message.content

def save_brief_to_file(keyword: str, brief: str):
    filename = f"content_brief_{keyword.replace(' ', '_')}.md"
    with open(filename, "w", encoding="utf-8") as f:
        f.write(f"# Content Brief: {keyword}\n\n{brief}")
    print(f"Brief saved to {filename}")

if __name__ == "__main__":
    target_keyword = "build AI content brief with Python"

    print(f"Fetching top results for '{target_keyword}'...")
    results = get_top_results(target_keyword)

    print("Generating content brief with GPT...")
    brief = generate_content_brief(target_keyword, results)

    print("\n=== Generated Content Brief ===\n")
    print(brief)

    save_brief_to_file(target_keyword, brief)

Enter fullscreen mode Exit fullscreen mode

How It Works

  1. Send keyword to TalorData SERP API
  2. Get back clean structured results
  3. Format results and send to GPT
  4. GPT generates a complete content brief
  5. Brief saved to markdown file

Advanced Features

Check multiple locations

def get_top_results_location(keyword, location):
    data["location"] = location
    # ... rest of the code

Enter fullscreen mode Exit fullscreen mode

Bulk generation

keywords = ["how to build a content brief", "SEO tips for beginners"]

for kw in keywords:
    results = get_top_results(kw)
    brief = generate_content_brief(kw, results)
    save_brief_to_file(kw, brief)

Enter fullscreen mode Exit fullscreen mode

Cost Breakdown

  • Each content brief: 1 SERP call ($0.001) + 1 GPT call (~$0.002) = $0.003 total
  • 100 briefs: Just $0.30
  • 1,000 briefs: $3.00

Wrapping Up

Building an AI-powered content brief generator with Python and SERP API is surprisingly simple. Instead of spending hours on manual research, you can get a complete brief in seconds.
TalorData makes this even better because:

  • No credit card required to start — build this entire project for free
  • Simple pricing at $1.00 per 1,000 requests
  • Clean API that just works

Have you built any SEO tools with SERP API before? What's your favorite use case? Drop a comment below!

Top comments (0)