API Key Text to Speech: Getting Started in 5 Minutes
Getting from zero to working text-to-speech audio takes five minutes if you follow these steps. This guide covers getting an API key, making your first request, and securing the key so it doesn't end up in a public repository.
Step 1: Get a TTS API Key
For Speeko:
- Go to speekoapp.com/register
- Create an account — no credit card required
- Receive $5 free credit automatically
- Navigate to the dashboard → API Keys
- Click "Generate New Key"
- Copy the key — it looks like
sk-speeko-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Important: API keys are shown once. If you close the dialog without copying, you'll need to generate a new one.
Step 2: Store the Key Securely
Never hardcode an API key in your code. It will end up in git history and potentially exposed.
Set it as an environment variable:
# Add to ~/.zshrc or ~/.bashrc
export SPEEKO_API_KEY="sk-speeko-your-key-here"
# Reload
source ~/.zshrc
# Verify
echo $SPEEKO_API_KEYIn a .env file (for projects):
# .env
SPEEKO_API_KEY=sk-speeko-your-key-here# Python: load with python-dotenv
from dotenv import load_dotenv
import os
load_dotenv()
api_key = os.environ["SPEEKO_API_KEY"]// Node.js: load with dotenv
import 'dotenv/config';
const apiKey = process.env.SPEEKO_API_KEY;Critical: add .env to .gitignore:
echo ".env" >> .gitignore
git add .gitignore
git commit -m "Ignore .env files"If you accidentally commit a key, treat it as compromised — rotate it immediately in the dashboard.
Step 3: Make Your First Request
curl:
curl -X POST https://api.speekoapp.com/v1/tts \
-H "X-API-Key: $SPEEKO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Hello! My API key works.", "voice": "en-US-1", "format": "mp3"}' \
--output first-request.mp3
# macOS: play it
afplay first-request.mp3
# Linux: play it
mpg123 first-request.mp3Python:
import requests
import os
api_key = os.environ["SPEEKO_API_KEY"]
response = requests.post(
"https://api.speekoapp.com/v1/tts",
headers={
"X-API-Key": api_key,
"Content-Type": "application/json",
},
json={
"text": "Hello! My API key works.",
"voice": "en-US-1",
"format": "mp3",
},
)
response.raise_for_status()
with open("first-request.mp3", "wb") as f:
f.write(response.content)
print(f"Success! Generated {len(response.content):,} bytes of audio.")Node.js:
import { writeFileSync } from 'fs';
const response = await fetch('https://api.speekoapp.com/v1/tts', {
method: 'POST',
headers: {
'X-API-Key': process.env.SPEEKO_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: 'Hello! My API key works.',
voice: 'en-US-1',
format: 'mp3',
}),
});
if (!response.ok) {
const error = await response.text();
throw new Error(`TTS failed: ${response.status} - ${error}`);
}
const buffer = Buffer.from(await response.arrayBuffer());
writeFileSync('first-request.mp3', buffer);
console.log(`Success! Generated ${buffer.length.toLocaleString()} bytes.`);Understanding the Authentication Header
The X-API-Key header is specific to Speeko. Other providers use different authentication:
| Provider | Auth Header | Format |
|---|---|---|
| Speeko | X-API-Key: sk-speeko-... |
Custom header |
| OpenAI | Authorization: Bearer sk-... |
Bearer token |
| Google Cloud | Authorization: Bearer [access-token] |
OAuth token |
| AWS Polly | AWS SigV4 signature | boto3 SDK handles it |
| ElevenLabs | xi-api-key: ... |
Custom header |
API Key Security Best Practices
Principle of least privilege: If your API provider supports scoped keys (read-only, specific endpoints), use the most limited key that works for your use case.
Never in client-side code: API keys in JavaScript running in a browser are visible to anyone who opens DevTools. Call TTS from your backend, not from the browser.
// WRONG — key exposed to browser users
const response = await fetch('https://api.speekoapp.com/v1/tts', {
headers: { 'X-API-Key': 'sk-speeko-...' }, // Visible in browser DevTools
});
// RIGHT — key stays on your server
// Browser calls your backend:
const audio = await fetch('/api/speak?text=Hello');
// Your backend calls Speeko with the key:
// X-API-Key: process.env.SPEEKO_API_KEYRotate keys regularly: Create a new key, update your deployment, then delete the old one. Monthly rotation is reasonable for production keys.
Separate keys per environment: Use different keys for development, staging, and production. If a dev key leaks, production is unaffected.
Monitor usage: Check your dashboard for unexpected usage spikes — they may indicate a leaked key.
Handling Authentication Errors
def make_tts_request(text: str) -> bytes:
try:
response = requests.post(
"https://api.speekoapp.com/v1/tts",
headers={"X-API-Key": os.environ["SPEEKO_API_KEY"]},
json={"text": text, "voice": "en-US-1", "format": "mp3"},
timeout=30,
)
if response.status_code == 401:
raise ValueError("API key invalid or missing. Check SPEEKO_API_KEY env var.")
if response.status_code == 403:
raise ValueError("API key doesn't have permission for this operation.")
if response.status_code == 429:
raise RuntimeError("Rate limited. Reduce request frequency.")
response.raise_for_status()
return response.content
except KeyError:
raise ValueError("SPEEKO_API_KEY environment variable not set.")Checking Your API Key Status
Before running a batch job, verify your key is valid and check your remaining balance:
curl https://api.speekoapp.com/v1/account \
-H "X-API-Key: $SPEEKO_API_KEY"Response:
{
"status": "active",
"credits_remaining_usd": 4.73,
"characters_remaining": 157667,
"rate_limit": {
"requests_per_minute": 60,
"concurrent_requests": 10
}
}You can also read rate limit state from response headers on any API call:
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 58
X-RateLimit-Reset: 1716400860X-RateLimit-Reset is a Unix timestamp. If Remaining hits 0, wait until that timestamp before retrying.
Multiple API Keys for Different Projects
If you build multiple products on Speeko, use a separate API key per project. Benefits:
- Usage tracking: See per-project costs in the dashboard without manual breakdowns
- Independent rotation: Rotate a key for one project without affecting others
- Access control: Share a key with a contractor without exposing your main key
- Budget alerts: Set spending limits per key if the dashboard supports it
Create as many keys as needed — there's no limit on the number of active API keys per account.
Next Steps
You have a working API key and can generate audio. Common next steps:
- Handle long text by chunking
- Reduce costs with caching
- Control pronunciation with SSML
- Stream audio for real-time apps
Start at speekoapp.com/register — $5 free credit, no card required.