IntegrationsBeginner

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.

9 minBeginner

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.

zsh — yt-scripts
$pip install anthropic
$export ANTHROPIC_API_KEY=sk-ant-...
$

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.

script.py
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

zsh — yt-scripts
$python script.py
HOOK
You have paid a tip your whole life and never knew where it goes.
...
CTA
Subscribe if you want the money side of everyday life explained.
$
draft.md — script editor
Explorer
script.py
draft.md
topics.txt
scripts/draft.md
1# Tipping explained
2
3## HOOK
4You have paid a tip your whole life...
5
6## BODY
71. Where the money actually goes
82. Why the percentage keeps climbing
93. ...
Paste the output into your editor and trim from there.
Feed it your voice
Paste two or three of your past scripts into the system prompt as examples. Claude will mirror your sentence length and tone far better than a generic prompt does.

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

Tags
#claude#anthropic#scripting#api#youtube