Step-by-step setup for every API in the automation pipeline —
OpenAI (scripts + TTS), Pexels, YouTube, and more
An API (Application Programming Interface) is a doorway into a software service that allows your code to use that service's capabilities programmatically. When your automation system generates a script, it is sending a request through OpenAI's API doorway and receiving a script back. When it generates a voiceover, it sends that script text back through OpenAI's TTS API and receives a high-quality audio file back — all through the same API key, the same account, the same integration.
You do not need to understand the code deeply to use APIs effectively. What you need to understand is: API key security, quota limits, and error handling. This guide covers all three for every API in the UnlockedMagick pipeline.
"APIs are the nervous system of automation. Master them and you control a machine that never sleeps. Ignore them and you're still doing everything manually."
Go to platform.openai.com and create an account. You will need a phone number for verification. New accounts receive $5 in free credits — enough to generate approximately 500 scripts before billing begins.
In the top-right menu, click your profile → View API Keys. Click "Create new secret key." Name it descriptively (e.g., "UnlockedMagick-Production"). Copy it immediately — OpenAI does not show it again after creation.
Go to Settings → Billing → Usage Limits. Set a hard monthly spending limit (recommended: start at $20/month). This prevents unexpected charges if your automation system runs unexpectedly at high volume.
For script generation, use gpt-4o for highest quality or gpt-4o-mini for cost optimization (80% the quality at 10% the cost). Set temperature to 0.7 — high enough for natural language variation, low enough for structured output.
Always set a max_tokens limit on your requests — approximately 1,500 tokens for an 8–10 minute script. Without this, runaway requests can consume your entire monthly budget in minutes.
New OpenAI accounts receive $5 free credits. To maximize free usage: use gpt-4o-mini for all non-critical scripts, batch your requests during off-peak hours, and use prompt caching (repeat the same system prompt across requests — OpenAI caches it and charges less for subsequent calls).
The UnlockedMagick pipeline uses OpenAI's native Text-to-Speech API for all voiceover generation. No separate account, no separate subscription — the same OpenAI API key you already set up in Chapter 2 handles both script generation and audio output.
OpenAI TTS is accessed through the same API key as GPT-4o. There is no separate TTS account to create. If you completed Chapter 2, you are already set up. Add your key to the UnlockedMagick dashboard under Settings → API Keys and TTS is active automatically.
OpenAI TTS offers six voices: alloy, echo, fable, onyx, nova, and shimmer. For financial and business content, onyx delivers the most authoritative tone. For lifestyle and general educational content, nova performs best. Test all six on a 30-second script sample before committing to a channel voice.
Use tts-1-hd for all production renders — it produces noticeably higher fidelity audio with less artifacting than the standard tts-1 model. Use tts-1 only for draft previews and testing, where audio quality is not the priority. The cost difference is minimal at automation scale.
The OpenAI TTS endpoint (/v1/audio/speech) accepts these key parameters:
model: "tts-1-hd" — always use HD for final rendersvoice: "onyx" — best for authoritative, professional contentspeed: 0.95 — slightly below default (1.0) for a more deliberate, trustworthy delivery paceresponse_format: "mp3" — optimal compression for video pipeline useOpenAI TTS charges approximately $0.015 per 1,000 characters (HD model). A 1,000-word script contains roughly 5,500 characters — approximately $0.08 per video. At 3 videos/day, that is roughly $7/month in TTS costs alone, integrated into your existing OpenAI spending limit. To minimize costs further: strip all stage directions and formatting markers from scripts before sending to TTS, and cache audio files locally — never regenerate voiceover for a script that already has audio.
Go to pexels.com/api and click "Get Started." Create an account and describe your use case (video automation platform). API keys are approved within minutes. The Pexels API is completely free with generous rate limits (200 requests/hour, 20,000/month).
All Pexels API requests require your key in the Authorization header: Authorization: YOUR_API_KEY. No "Bearer" prefix — just the key directly.
The Pexels video search endpoint (/v1/videos/search) accepts keyword queries. For automation, your system should extract the 2–3 core semantic concepts from each script section and query them independently. A script section about "compound interest" should query "money growth," "financial charts," and "savings" — not "compound interest" literally, which returns few results.
Always request orientation=landscape and size=medium or large for YouTube-quality footage. Store downloaded footage locally and implement a deduplication check — the same clip appearing twice in one video destroys production quality.
Unlike the other APIs which use simple API keys, YouTube requires OAuth 2.0 authentication — a more complex but more secure flow that links your specific YouTube channel to your automation system.
Go to console.cloud.google.com. Click "New Project." Name it (e.g., "UnlockedMagick-Automation"). Wait 30–60 seconds for creation.
In your project, go to APIs & Services → Library. Search "YouTube Data API v3." Click Enable. This may take 2–3 minutes to propagate.
Go to APIs & Services → Credentials → Create Credentials → OAuth Client ID. Select "Desktop App" as the application type. Download the credentials JSON file. Store it securely — this file grants access to your YouTube channel.
Go to OAuth Consent Screen → Test Users. Add the Google account email connected to your YouTube channel. Until your app is verified (which is optional for personal automation), only test users can authorize it.
UnlockedMagick handles this automatically when you add your channel credentials in the dashboard. You'll see a Google authorization screen — click Allow. Your refresh token is stored securely and used for all future uploads without requiring re-authorization.
The YouTube Data API v3 has a default quota of 10,000 units per day. Video uploads cost 1,600 units each — meaning you can upload approximately 6 videos per day on the default quota. To upload more: request a quota increase through the Google Cloud Console (approval typically takes 2–7 business days and is usually granted for legitimate automation use cases).
API key security is not optional. A leaked OpenAI key can generate thousands of dollars in charges in hours. A leaked YouTube OAuth credential can result in your channel being taken over. Treat API keys with the same security discipline as banking passwords.
At 3 videos/day, your monthly API costs on the Starter Stack should be $30–60. This can balloon to $300+ if you don't implement cost controls. The three most important controls:
Set up APIs in this order: (1) OpenAI — handles both script generation AND voiceover (TTS) through one key. (2) Pexels — needed for footage. (3) YouTube — needed for publishing. Each API is independent — a failure in one does not block others. Add keys to UnlockedMagick dashboard under Settings → API Keys and the system handles the rest.