# Super Programmatic SEO - External API Documentation

## Overview

Super Programmatic SEO integrates with two external APIs to provide AI-powered content generation and professional image sourcing.

## OpenAI API Integration

### Purpose
Generates high-quality, SEO-optimized content using OpenAI's ChatGPT models.

### API Key Setup
1. Visit [OpenAI Platform](https://platform.openai.com/api-keys)
2. Create an account or sign in
3. Generate a new API key
4. Copy the key (starts with `sk-`)
5. Paste it in the plugin's API Settings page

### Usage in Plugin
- **Endpoint**: `https://api.openai.com/v1/chat/completions`
- **Model**: `gpt-4o` (configurable)
- **Authentication**: Bearer token via API key
- **Rate Limits**: Based on your OpenAI plan

### Cost Information
- **Pricing**: Pay-per-use starting at $0.002 per 1K tokens
- **Typical Article**: ~2,000-5,000 tokens ($0.004-$0.010)
- **Free Tier**: $5 credit for new accounts

### Security
- API keys are stored securely in WordPress options table
- All requests include proper error handling
- No sensitive data is logged or transmitted unnecessarily

## Pexels API Integration

### Purpose
Provides high-quality stock images to enhance generated articles.

### API Key Setup
1. Visit [Pexels API](https://www.pexels.com/api/)
2. Create a free account
3. Generate an API key
4. Copy the key
5. Paste it in the plugin's API Images settings

### Usage in Plugin
- **Endpoint**: `https://api.pexels.com/v1/search`
- **Authentication**: API key in Authorization header
- **Rate Limits**: 200 requests/hour (free), higher limits on paid plans

### Cost Information
- **Free Tier**: 200 requests/hour
- **Paid Plans**: Starting at $9.99/month for higher limits
- **Images**: All images are free to use with attribution

### Security
- API keys are stored securely in WordPress options table
- Images are downloaded and processed locally
- WebP conversion for optimal performance

## Error Handling

### OpenAI API Errors
- **Invalid API Key**: User-friendly error message with setup instructions
- **Rate Limit Exceeded**: Automatic retry with exponential backoff
- **Content Filter**: Graceful fallback to alternative prompts
- **Network Issues**: Clear error messages and retry suggestions

### Pexels API Errors
- **Invalid API Key**: Setup instructions provided
- **No Images Found**: Graceful degradation without images
- **Rate Limit**: Automatic retry with delays
- **Download Failures**: Continues generation without images

## Privacy and Data Handling

### Data Transmission
- **OpenAI**: Only article prompts and generated content
- **Pexels**: Only search terms for image queries
- **No Personal Data**: Company details are used only in content generation

### Data Storage
- **API Keys**: Encrypted in WordPress options table
- **Generated Content**: Stored as WordPress posts
- **Images**: Downloaded and stored in WordPress media library

### Compliance
- **GDPR**: All data processing is done locally
- **CCPA**: No personal data is shared with third parties
- **SOC 2**: OpenAI and Pexels are SOC 2 compliant

## Best Practices

### API Key Management
1. Use environment variables for production
2. Regularly rotate API keys
3. Monitor usage and costs
4. Set up billing alerts

### Content Quality
1. Review generated content before publishing
2. Customize prompts for your niche
3. Use appropriate writing styles
4. Add manual editing for brand voice

### Performance Optimization
1. Enable image caching
2. Use appropriate model settings
3. Monitor API response times
4. Implement proper error handling

## Troubleshooting

### Common Issues

**OpenAI API Key Not Working**
- Verify the key is correct and active
- Check if you have sufficient credits
- Ensure the key has proper permissions

**Pexels Images Not Loading**
- Verify API key is valid
- Check rate limit status
- Ensure proper image permissions

**Slow Content Generation**
- Check API response times
- Consider using faster models
- Optimize prompt length

### Support Resources
- [OpenAI Documentation](https://platform.openai.com/docs)
- [Pexels API Documentation](https://www.pexels.com/api/documentation/)
- [Plugin Support Forum](https://wordpress.org/support/plugin/super-programmatic-seo/)

