API Credentials Guide¤
This guide explains how to obtain API credentials for all supported AI and social media services in PyTube.
Table of Contents¤
- AI Services
- OpenAI
- Anthropic Claude
- Google Gemini
- Cohere
- Social Media Platforms
- Twitter/X
- Mastodon
- Bluesky
AI Services¤
OpenAI¤
Required: api_key
- Sign up: Go to platform.openai.com and create an account
- API Keys: Navigate to platform.openai.com/api-keys
- Create Key: Click "Create new secret key"
- Copy Key: Save the key immediately (it won't be shown again)
- Billing: Add payment method at platform.openai.com/account/billing
Configuration:
ai_service: "openai"
openai:
api_key: "sk-..."
model: "gpt-3.5-turbo" # or gpt-4, gpt-4o
organization: "org-..." # Optional
Pricing: - GPT-3.5-turbo: ~$0.002 per 1K tokens - GPT-4: ~$0.03-0.06 per 1K tokens - Check current pricing at openai.com/pricing
Anthropic Claude¤
Required: api_key
- Sign up: Go to console.anthropic.com and create an account
- API Keys: Navigate to Account Settings → API Keys
- Create Key: Click "Create Key"
- Copy Key: Save the key immediately
- Credits: Add credits or payment method in billing section
Configuration:
ai_service: "anthropic"
anthropic:
api_key: "sk-ant-..."
model: "claude-3-sonnet-20240229" # or claude-3-opus-20240229, claude-3-haiku-20240307
max_tokens: 1000
Pricing: - Claude 3 Haiku: ~$0.25 per 1M tokens (input), $1.25 per 1M tokens (output) - Claude 3 Sonnet: ~$3 per 1M tokens (input), $15 per 1M tokens (output) - Claude 3 Opus: ~$15 per 1M tokens (input), $75 per 1M tokens (output)
Google Gemini¤
Required: api_key
- Sign up: Go to makersuite.google.com (Google AI Studio)
- Get API Key: Click on "Get API key" in the left sidebar
- Create Key: Choose "Create API key in new project" or select existing project
- Copy Key: Save the generated API key
- Enable: The Gemini API is automatically enabled
Configuration:
ai_service: "google"
google:
api_key: "AIza..."
model: "gemini-pro" # or gemini-pro-vision for multimodal
safety_settings:
harassment: "BLOCK_MEDIUM_AND_ABOVE"
hate_speech: "BLOCK_MEDIUM_AND_ABOVE"
Pricing: - Gemini Pro: Free tier available (60 queries per minute) - Paid tier: $0.00025 per 1K characters (input), $0.0005 per 1K characters (output)
Cohere¤
Required: api_key
- Sign up: Go to dashboard.cohere.com and create an account
- API Keys: Navigate to API Keys section
- Create Key: Click "Create Trial Key" or "Create Production Key"
- Copy Key: Save the key immediately
- Upgrade: Trial keys have limited usage; upgrade for production use
Configuration:
ai_service: "cohere"
cohere:
api_key: "..."
model: "command" # or command-light, command-nightly
Pricing: - Trial: Free with limited usage - Production: Starting at $0.40 per 1M tokens - Check cohere.com/pricing for details
Social Media Platforms¤
LinkedIn¤
Required: access_token
, company_id
(optional)
LinkedIn uses OAuth 2.0, which is complex for personal use. Here are two approaches:
Option 1: Using LinkedIn Developer App (Recommended for organizations)¤
- Create App: Go to linkedin.com/developers and create an app
- Verify App: Complete verification process (requires company page admin access)
- Products: Request access to "Share on LinkedIn" and "Marketing Developer Platform"
- OAuth Flow: Implement OAuth 2.0 flow to get access token
- Company ID: Find in your LinkedIn company page URL
Option 2: Using Third-Party Tools (Easier for personal use)¤
- Use tools like LinkedIn API Console
- Or use Postman's LinkedIn collection to generate tokens
- Note: Personal access tokens may have limited scope
Configuration:
social_media_service: "linkedin"
linkedin:
access_token: "AQX..."
refresh_token: "..." # Optional, for auto-refresh
client_id: "..." # From your app
client_secret: "..." # From your app
company_id: "12345" # Optional, for company posts
Twitter/X¤
Required: api_key
, api_secret
, access_token
, access_token_secret
- Developer Account: Apply at developer.twitter.com
- Create Project: Once approved, create a new project and app
- Keys: In your app settings, find:
- API Key (Consumer Key)
- API Secret (Consumer Secret)
- Access Tokens: Generate Access Token and Secret
- Permissions: Set app permissions to "Read and Write"
Configuration:
social_media_service: "twitter"
twitter:
api_key: "..." # Also called Consumer Key
api_secret: "..." # Also called Consumer Secret
access_token: "..."
access_token_secret: "..."
bearer_token: "..." # Optional, for app-only auth
Note: Twitter API access now requires paid tier ($100/month for Basic)
Mastodon¤
Required: access_token
, instance_url
- Choose Instance: Select your Mastodon instance (e.g., mastodon.social, fosstodon.org)
- Create App: Go to Preferences → Development → New Application
- Permissions: Select required scopes:
write:statuses
(for posting)write:media
(for images)- Create: Submit and create the application
- Access Token: Copy the access token from the app details
Configuration:
social_media_service: "mastodon"
mastodon:
instance_url: "https://mastodon.social" # Your instance
access_token: "..."
visibility: "public" # or unlisted, private, direct
Bluesky¤
Required: handle
, app_password
- Account: Create account at bsky.app
- App Password: Go to Settings → App Passwords
- Create: Click "Add App Password"
- Name: Give it a descriptive name (e.g., "PyTube")
- Copy: Save the generated app password
Configuration:
social_media_service: "bluesky"
bluesky:
handle: "yourhandle.bsky.social" # Your full handle
app_password: "xxxx-xxxx-xxxx-xxxx" # Generated app password
Note: Never use your main account password; always use app-specific passwords
Security Best Practices¤
- Never commit credentials: Always use
config_local.yaml
(git-ignored) - Use environment variables: For production deployments
- Rotate keys regularly: Especially for production use
- Limit permissions: Only grant necessary scopes/permissions
- Monitor usage: Check API dashboards for unusual activity
Environment Variables Alternative¤
Instead of storing in config files, you can use environment variables:
# AI Services
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
# Social Media
export LINKEDIN_ACCESS_TOKEN="..."
export TWITTER_API_KEY="..."
Then reference in your config:
openai:
api_key: ${OPENAI_API_KEY}
Troubleshooting¤
Common Issues¤
- "Invalid API Key":
- Check for extra spaces or quotes
- Ensure key hasn't been revoked
-
Verify you're using the correct service
-
"Rate limit exceeded":
- Check your plan limits
- Implement exponential backoff
-
Consider upgrading tier
-
"Insufficient permissions":
- Review OAuth scopes (social media)
- Check API product access (LinkedIn)
-
Verify app permissions
-
"Configuration not found":
- Ensure config_local.yaml exists
- Check YAML formatting
- Verify service name spelling
Cost Estimation¤
For a typical conference with 50 talks: - AI Costs: ~$5-20 depending on model choice - Social Media: Usually free (except Twitter Basic API)
Support Links¤
- OpenAI: help.openai.com
- Anthropic: support.anthropic.com
- Google AI: ai.google.dev/support
- Cohere: docs.cohere.com
- LinkedIn: linkedin.com/help/linkedin
- Twitter: developer.twitter.com/support
- Mastodon: Instance-specific support
- Bluesky: blueskyweb.xyz/support