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

Google Resolves AI Mode Traffic Attribution Issue in Analytics

Google Resolves AI Mode Traffic Attribution Issue in Analytics

Marketing Workflow Templates

Marketing Workflow Templates

Featured
Markifact
Markifact

Verified Sponsor

Verified Sponsor

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

Verified Sponsor
Google launches AI search guidelines urging focus on unique content over visit metrics

Google launches AI search guidelines urging focus on unique content over visit metrics

Google Search Central
Google Search Central

Official Source

Official Source

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

Official Source
Google launches AI Mode for shopping with new virtual try-on feature using personal photos Trending ️‍🔥

Google launches AI Mode for shopping with new virtual try-on feature using personal photos

Google
Google

Official Source

Official Source

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

Official Source
OpenAI launches Codex AI agent for parallel software engineering tasks in ChatGPT

OpenAI launches Codex AI agent for parallel software engineering tasks in ChatGPT

OpenAI
OpenAI

Official Source

Official Source

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

Official Source
Google tests replacing I’m Feeling Lucky button with AI Mode feature

Google tests replacing I’m Feeling Lucky button with AI Mode feature

Google Updates Image SEO Best Practices to Recommend Consistent URLs for Images

Google Updates Image SEO Best Practices to Recommend Consistent URLs for Images

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 Unveils Generative AI for 3D Product Visualizations in Online Shopping

Google Unveils Generative AI for 3D Product Visualizations in Online Shopping

Google
Google

Official Source

Official Source

Google 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