How to Generate YouTube Video Scripts with the Claude API
Turn a one-line topic into a structured, hook-first video script by calling the Anthropic Messages API from a small script.
A blank document is the slowest part of making a video. This guide calls Claude through the Anthropic Messages API to draft a structured script (hook, body beats, call to action) from a single topic line, so you start editing instead of staring.
What you need
- An Anthropic API key from console.anthropic.com
- Python 3.9+ or Node 18+ (this guide shows Python)
- A topic and a target length in mind
Step 1: Install the SDK and set your key
Install the official SDK and export your key as an environment variable so it never lives in the code.
Step 2: Write a prompt that enforces structure
A system prompt that names the sections you want produces a script you can shoot from. Ask for a hook in the first two lines, three to five body beats, and a closing call to action.
import os
from anthropic import Anthropic
client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
SYSTEM = (
"You write tight YouTube scripts. Output sections in order: "
"HOOK (2 lines), BODY (3 to 5 beats, each a short paragraph), "
"CTA (1 line). Plain spoken language, no stage directions."
)
def write_script(topic, minutes):
msg = client.messages.create(
model="claude-opus-4-5",
max_tokens=1500,
system=SYSTEM,
messages=[{
"role": "user",
"content": f"Topic: {topic}. Target length: {minutes} minutes.",
}],
)
return msg.content[0].text
if __name__ == "__main__":
print(write_script("How tipping works in the US", 6))Step 3: Run it
Result
You get a labeled HOOK, BODY, and CTA in seconds. Loop over a topics.txt file to draft a week of scripts in one run, then edit each into your own words.
Watch related tutorials
1:42:18
28:14
41:09
9:47
8:23
52:31