UnlockedMagick · Guide 09

API Setup Mastery

Step-by-step setup for every API in the automation pipeline —
OpenAI (scripts + TTS), Pexels, YouTube, and more

By Golden Alien · UnlockedMagick

Table of Contents
  1. Understanding APIs — What They Are and Why They Matter
  2. OpenAI API — Script Generation Engine
  3. OpenAI TTS API — Voice Synthesis
  4. Pexels API — Stock Footage
  5. YouTube Data API v3 — Automated Publishing
  6. Securing and Managing API Keys
  7. Quota Management and Cost Control
  8. Troubleshooting Common API Errors

Chapter 1Understanding APIs

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."

Chapter 2OpenAI API Script Generation

Getting Your API Key

Step 01
Create an OpenAI account

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.

Step 02
Navigate to API Keys

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.

Step 03
Set spending limits

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.

Recommended Model Configuration

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.

Free Tier Strategy

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).

Chapter 3OpenAI TTS API Voice Synthesis

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.

No Additional Setup Required

Step 01
Use your existing OpenAI API key

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.

Step 02
Choose your voice

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.

Step 03
Select the correct model tier

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.

Optimal API Parameters

The OpenAI TTS endpoint (/v1/audio/speech) accepts these key parameters:

Cost Optimization

OpenAI 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.

Chapter 4Pexels API Stock Footage

Step 01
Get your free API key

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).

Step 02
Add key to your Authorization header

All Pexels API requests require your key in the Authorization header: Authorization: YOUR_API_KEY. No "Bearer" prefix — just the key directly.

Semantic Video Search Strategy

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.

Chapter 5YouTube Data API v3 Auto-Publishing

Setting Up OAuth 2.0

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.

Step 01
Create a Google Cloud Project

Go to console.cloud.google.com. Click "New Project." Name it (e.g., "UnlockedMagick-Automation"). Wait 30–60 seconds for creation.

Step 02
Enable YouTube Data API v3

In your project, go to APIs & Services → Library. Search "YouTube Data API v3." Click Enable. This may take 2–3 minutes to propagate.

Step 03
Create OAuth Credentials

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.

Step 04
Add your YouTube account to test users

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.

Step 05
Run authorization flow

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.

Daily Quota Management

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).

Chapter 6Securing API Keys

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.

Chapter 7Quota Management and Cost Control

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:

  1. Hard spending caps on OpenAI — set at 120% of your expected monthly usage (covers both GPT-4o scripts and TTS audio)
  2. Request logging — log every API call with cost estimate so you can identify unexpected usage immediately
  3. Caching — store generated scripts and voiceovers locally so you never regenerate content that already exists

Chapter 8Troubleshooting Common Errors

Error Reference
Your Setup Checklist

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.