Automating Pinterest Pin Generation with the Claude API
A Pinterest pin generator is a script that reads a blog post, calls a large language model to produce SEO-optimised pin metadata, and uploads the result to Pinterest — automating a publishing chore rather than the writing itself.
I have been slowly automating the repetitive parts of running this blog. Not the writing ideas — that stays human. But the publishing chores: resizing images, preparing metadata, checking links. The latest experiment was a Pinterest pin generator.
The script reads a Jekyll post from _posts/, sends a cleaned-up version to Claude, and receives back a pin title, description, hashtags, and a short image excerpt. The script then renders a 1000×1500 JPEG and uploads it to Pinterest via the v5 API.
Before I ran this over my whole archive, I had one very practical question: how much will this actually cost?
There is a specific kind of programmer’s dread that kicks in when you are about to loop a script over your entire post archive — not “will it work?” but “will it charge me forty dollars while I’m not watching?” So I decided to calculate it properly: not a rough guess, but an exact breakdown of what the script sends, how many tokens that produces, and what the API charges for it.
This post walks through that calculation. If you are building something similar, the methodology is reusable for any prompt-based workflow.
Claude API Prompt Structure for Pinterest Pin Generation
The script calls claude-sonnet-4-6 with a single user message. There is no system prompt. The message is built from four parts:
- A fixed instruction block describing the task
- The post’s existing title (from YAML front matter)
- The post’s existing tags (from YAML front matter)
- The post body, stripped of markdown syntax and truncated to 4,000 characters
After Claude responds, the script parses the JSON and enforces character limits: title to 100 characters, description to 500, hashtags to 5, excerpt to 200.
Here is the exact prompt template the script uses:
prompt = f"""You are an expert Pinterest SEO strategist.
Analyse the blog post below and return a JSON object with these exact keys:
"title" – Pinterest pin title, max 100 characters, compelling and keyword-rich
"description" – Pin description, max 500 characters, natural tone, rich with keywords
"hashtags" – Array of up to 5 relevant hashtags WITHOUT the # symbol
"excerpt" – 1–2 short punchy sentences (max 200 chars) to overlay on the pin image
Existing post title : {existing_title}
Existing tags : {', '.join(existing_tags)}
POST CONTENT:
{content_plain}
Return ONLY the JSON object, no markdown, no extra text."""
Prompt Anatomy — Where the Characters Come From
🔒 Subscribe to keep reading.
Token Estimation for claude-sonnet-4-6 API Calls
🔒 Subscribe to keep reading.
Claude API Cost Calculation Per Pinterest Pin
🔒 Subscribe to keep reading.
Pinterest Pin Generation Cost at Scale (1 to 10,000 Pins)
🔒 Subscribe to keep reading.
The 4,000-Character Content Truncation Limit
🔒 Subscribe to keep reading.
Anthropic Message Batches API: Asynchronous Batch Pattern
🔒 Subscribe to keep reading.
Pinterest Pin Generation Cost Summary
🔒 Subscribe to keep reading.
References
🔒 Subscribe to keep reading.
You've hit a Deep Dive tutorial.
I spend dozens of hours researching, coding, and breaking things to write these guides. This content is free, but reserved for my subscriber community. Drop your email below to unlock this guide (and all past/future deep dives):
Full content temporarily unavailable — refresh in a moment
Already a subscriber? Use the magic link from your last newsletter, or reset your password.
Log in to unlock
New subscribers get an inbox mail: Set a password to unlock articles. The form does not log you in — use the same email afterwards.