Authentication
Secure your API requests with API key authentication. Learn how to generate, manage, and use your API keys safely.
API Key Authentication #
YourVoic API uses API keys to authenticate requests. Include your API key in the X-API-Key header of every request.
Header
X-API-Key: yv_live_1234567890abcdef
Keep Your API Keys Secure!
Never expose API keys in client-side code, public repositories, or logs. Use environment variables and server-side requests.
Never expose API keys in client-side code, public repositories, or logs. Use environment variables and server-side requests.
Getting Your API Key #
- Visit yourvoic.com/signup to create a free account
- Go to Settings → API Keys
- Click "Create New Key" and give it a name
- Copy your key immediately - it won't be shown again!
Using Your API Key #
Include your API key in the X-API-Key header:
cURL
Terminal
curl -X POST "https://yourvoic.com/api/v1/tts/generate" \
-H "X-API-Key: yv_live_1234567890abcdef" \
-H "Content-Type: application/json" \
-d '{"text": "Hello world", "voice": "Peter"}'
Python
Python
import os
import requests
api_key = os.getenv("YOURVOIC_API_KEY")
headers = {
"X-API-Key": api_key,
"Content-Type": "application/json"
}
response = requests.post(
"https://yourvoic.com/api/v1/tts/generate",
headers=headers,
json={"text": "Hello world", "voice": "Peter"}
)
JavaScript
JavaScript
const apiKey = process.env.YOURVOIC_API_KEY;
const response = await fetch('https://yourvoic.com/api/v1/tts/generate', {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({ text: 'Hello world', voice: 'Peter' })
});
API Key Types #
| Type | Prefix | Use Case |
|---|---|---|
| Live Key | yv_live_ |
Production environments |
| Test Key | yv_test_ |
Development & testing |
💡 Best Practice: Use test keys during development and live keys in production to track usage separately.
Security Best Practices #
🔐 Environment Variables
Never hardcode API keys in source code
🚫 No Client-Side
Don't expose keys in frontend code
🔄 Rotate Keys
Generate new keys periodically
🔒 HTTPS Only
Always use encrypted connections
Using .env Files
.env (add to .gitignore!)
YOURVOIC_API_KEY=yv_live_1234567890abcdef
Error Responses #
If authentication fails, you'll receive one of these errors:
| Error Code | Status | Solution |
|---|---|---|
AUTH_MISSING_API_KEY |
401 | Add X-API-Key header |
AUTH_INVALID_API_KEY |
401 | Check for typos or generate new key |
AUTH_EXPIRED_API_KEY |
401 | Generate a new API key |
AUTH_REVOKED_API_KEY |
401 | Create a new API key |
Example Error Response
{
"success": false,
"error": {
"code": "AUTH_INVALID_API_KEY",
"message": "Invalid API key",
"resolution": "Check your API key for typos"
}
}
Managing Your API Keys #
Viewing Keys
See all your API keys in Settings → API Keys. You'll see key name, creation date, last used, and usage stats.
Revoking Keys
If you suspect a key has been compromised:
- Go to Settings → API Keys
- Find the compromised key
- Click "Revoke" button
- Create a new key and update your apps