Clustering SEO Keywords using OpenAI Batch API, Saving 50% in Cost

May 06, 2024 at 11:03:29 AM

TL;DR OpenAI's Batch API allows grouped requests at half the cost, ideal for non-immediate tasks. It's useful for large-scale SEO tasks like keyword clustering. The API works with all OpenAI’s models, including GPT-3.5-turbo-16k and GPT-4-turbo. A Python guide demonstrates how to use the Batch API for clustering SEO keywords, including preparing a batch file in JSONL format, uploading the file, and retrieving results.

Clustering SEO Keywords using OpenAI Batch API, Saving 50% in Cost

OpenAI's Batch API allows users to send grouped requests at half the cost, ideal for tasks that can wait up to 24 hours. It's useful when immediate responses aren't necessary or when rate limits hinder executing many queries quickly.

Batch API is beneficial for scenarios like clustering SEO Keywords, Product Feed Optimization, and Document Summarization. It works with all OpenAI’s models, including GPT-3.5-turbo-16k and GPT-4-turbo.

To use the Batch API, prepare a batch file in JSONL format. For example, to cluster over 150,000 keywords, split this into two requests due to the GPT-4 turbo model's context limit of 128k tokens. Create a list of requests, each formatted as a dictionary containing your SEO keywords.

requests = [
 {
 "custom_id": "keyword_cluster_1",
 "method": "POST",
 "url": "/v1/completions",
 "body": {
 "model": "gpt-4-turbo",
 "prompt": f"{prompt} ['SEO', 'optimization', 'Google ranking']",
 },
 },
 {
 "custom_id": "keyword_cluster_2",
 "method": "POST",
 "url": "/v1/completions",
 "body": {
 "model": "gpt-4-turbo",
 "prompt": f"{prompt} ['backlinks', 'page authority', 'domain score']",
 },
 },
]

Convert your data to a JSONL file and upload it using the file API to obtain a file ID.

import json
from openai import OpenAI
client = OpenAI()
with open('seo_keywords.jsonl', 'w') as file:
 for request in requests:
 file.write(json.dumps(request) + '\n')
with open('seo_keywords.jsonl', 'rb') as file:
 batch_input_file = client.files.create(file=file, purpose='batch')

Submit the batch with one line of code and check the status and retrieve results after 12 to 18 hours.

batch = client.batches.create(input_file_id=batch_input_file.id, endpoint="/v1/completions", completion_window="24h")
status = client.batches.retrieve(batch.id)
if status['status'] == 'completed':
 output = client.files.content(batch.output_file_id)
 print(output)

The Batch API is a cost-effective tool for managing large-scale SEO tasks like keyword clustering, saving time and reducing costs.

Q&A

Have more questions on this topic? Ask our AI assistant for in-depth insights.

The Only Digital Marketing Feed You'll Ever Need.

Stay informed your way. Tailored updates when and how you want them. 100% Free.

10,000+ Users

500+ Sources

1000+ Tools

Or

Related Posts

OpenAI launches new tools for businesses to build AI agents more easily

OpenAI launches new tools for businesses to build AI agents more easily

OpenAI
OpenAI

Official Source

Official Source

OpenAI is a Official Source. The source has been verified by Swipe Insight team.

Official Source
No-code Marketing Platform

No-code Marketing Platform

Featured
Markifact
Markifact

Verified Sponsor

Verified Sponsor

Markifact is a Verified Sponsor. Want to get featured here? Contact us.

Verified Sponsor
Google Shuts Down Controversial Page Annotations Feature

Google Shuts Down Controversial Page Annotations Feature

Google for Developers
Google for Developers

Official Source

Official Source

Google for Developers is a Official Source. The source has been verified by Swipe Insight team.

Official Source
Google Updates Robots Meta Tag Documentation to Include AI Mode Feature

Google Updates Robots Meta Tag Documentation to Include AI Mode Feature

Google for Developers
Google for Developers

Official Source

Official Source

Google for Developers is a Official Source. The source has been verified by Swipe Insight team.

Official Source
Google Shopping Introduces New AI Tools for Fashion and Beauty

Google Shopping Introduces New AI Tools for Fashion and Beauty

Google Ads SEO +1 more
Google
Google

Official Source

Official Source

Google is a Official Source. The source has been verified by Swipe Insight team.

Official Source
OpenAI launches GPT-4.5 as its largest AI model Trending ️‍🔥

OpenAI launches GPT-4.5 as its largest AI model

OpenAI
OpenAI

Official Source

Official Source

OpenAI is a Official Source. The source has been verified by Swipe Insight team.

Official Source
Google Launches New Alerts for Personal Data Removal from Search Results

Google Launches New Alerts for Personal Data Removal from Search Results

Google
Google

Official Source

Official Source

Google is a Official Source. The source has been verified by Swipe Insight team.

Official Source
Deep Research now available to ChatGPT Plus users

Deep Research now available to ChatGPT Plus users

OpenAI
OpenAI

Official Source

Official Source

OpenAI is a Official Source. The source has been verified by Swipe Insight team.

Official Source

Related Tools

Markifact logo

Markifact

Verified Tool

Verified Tool

Markifact is a Verified Tool. Want to get this badge? Contact us.

Verified Tool

Marketing Workflows Powered by AI

Featured
Marketing Auditor logo

Marketing Auditor

Verified Tool

Verified Tool

Marketing Auditor is a Verified Tool. Want to get this badge? Contact us.

Verified Tool

Automated audits for Google Ads and Analytics.

Get Featured Here

Showcase your tool in this list.

Contact Us
Ahrefs logo

Ahrefs

SEO tools to boost traffic and rank higher

SEO
Surfer SEO logo

Surfer SEO

SEO content creation and optimization made easy

SEO
Sitebulb logo

Sitebulb

Efficient website crawler for better SEO audits

SEO
Screpy logo

Screpy

AI-Powered SEO and Web Analysis Simplified

SEO
Blogify logo

Blogify

Convert multimedia to SEO-optimized blogs fast

SEO
Answer the Public logo

Answer the Public

Unlock Consumer Insights for Content Creation

SEO
SEO Writing AI logo

SEO Writing AI

AI-powered SEO content in 1 click

SEO
SEO Stuff logo

SEO Stuff

Affordable SEO tools without monthly fees

SEO

Get Featured Here

Showcase your tool in this list.

Contact Us