> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/darkzOGx/youtube-automation-agent/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Providers

> Configure OpenAI, Google Gemini, Azure Speech, and other AI services for content generation

The YouTube Automation Agent uses multiple AI providers to generate high-quality content. This guide covers configuration and usage of each service.

## Overview

The system supports multiple AI providers with automatic fallback:

| Provider      | Purpose                        | Required | Fallback     |
| ------------- | ------------------------------ | -------- | ------------ |
| OpenAI        | Content, Images, TTS           | Yes      | None         |
| Google Gemini | Alternative content generation | No       | OpenAI       |
| Azure Speech  | High-quality TTS               | No       | OpenAI TTS   |
| ElevenLabs    | Premium voice generation       | No       | Azure/OpenAI |
| Replicate     | Advanced video generation      | No       | Slideshow    |

***

## OpenAI Configuration

OpenAI is the primary AI provider and is required for the system to function.

<Steps>
  <Step title="Get API Key">
    1. Sign up at [OpenAI Platform](https://platform.openai.com/)
    2. Navigate to [API Keys](https://platform.openai.com/api-keys)
    3. Create a new secret key
    4. Copy the key (starts with `sk-proj-` or `sk-`)
  </Step>

  <Step title="Configure in credentials.json">
    ```json theme={null}
    {
      "openai": {
        "apiKey": "sk-proj-...",
        "model": "gpt-4-turbo-preview"
      }
    }
    ```
  </Step>

  <Step title="Or use environment variable">
    ```bash theme={null}
    OPENAI_API_KEY=sk-proj-...
    ```
  </Step>
</Steps>

### Available Models

Select the model that best fits your needs:

<Tabs>
  <Tab title="GPT-4 Turbo (Recommended)">
    ```json theme={null}
    "model": "gpt-4-turbo-preview"
    ```

    **Best for:**

    * High-quality content generation
    * Complex script writing
    * SEO optimization
    * Nuanced storytelling

    **Cost:** \~$0.01 per 1K tokens (input), ~$0.03 per 1K tokens (output)
  </Tab>

  <Tab title="GPT-4">
    ```json theme={null}
    "model": "gpt-4"
    ```

    **Best for:**

    * Maximum quality
    * Premium content channels
    * Complex analysis

    **Cost:** \~$0.03 per 1K tokens (input), ~$0.06 per 1K tokens (output)
  </Tab>

  <Tab title="GPT-3.5 Turbo">
    ```json theme={null}
    "model": "gpt-3.5-turbo"
    ```

    **Best for:**

    * High-volume content
    * Budget-conscious operations
    * Simple content types

    **Cost:** \~$0.0005 per 1K tokens (input), ~$0.0015 per 1K tokens (output)
  </Tab>

  <Tab title="GPT-3.5 Turbo 16K">
    ```json theme={null}
    "model": "gpt-3.5-turbo-16k"
    ```

    **Best for:**

    * Long-form content
    * Extended scripts
    * Large context windows

    **Cost:** \~$0.003 per 1K tokens (input), ~$0.004 per 1K tokens (output)
  </Tab>
</Tabs>

### OpenAI Features Used

The system utilizes multiple OpenAI services:

#### 1. Text Generation (GPT)

Used for:

* Script writing
* Title and description generation
* SEO optimization
* Content strategy

```javascript theme={null}
// Configured model is used automatically
await openai.chat.completions.create({
  model: credentials.openai.model,
  messages: [...]
});
```

#### 2. Image Generation (DALL-E 3)

Used for:

* Video thumbnails
* Visual assets for videos
* Background images

```javascript theme={null}
await openai.images.generate({
  model: "dall-e-3",
  prompt: "...",
  size: "1792x1024",
  quality: "hd"
});
```

<Note>
  DALL-E 3 generates images in 16:9 aspect ratio (1792x1024) optimized for YouTube thumbnails and video content.
</Note>

#### 3. Text-to-Speech (TTS)

Used for:

* Video narration
* Voice-over generation

```javascript theme={null}
await openai.audio.speech.create({
  model: "tts-1-hd",
  voice: "nova",
  input: scriptText
});
```

<Accordion title="Available OpenAI TTS Voices">
  * **alloy** - Neutral, balanced
  * **echo** - Deep, authoritative
  * **fable** - British, warm
  * **onyx** - Deep, serious
  * **nova** - Friendly, clear (default)
  * **shimmer** - Soft, expressive
</Accordion>

***

## Google Gemini Configuration

Gemini can be used as an alternative or supplement to OpenAI for content generation.

<Steps>
  <Step title="Get Gemini API Key">
    1. Visit [Google AI Studio](https://makersuite.google.com/app/apikey)
    2. Click "Get API Key"
    3. Create or select a Google Cloud project
    4. Copy the generated API key
  </Step>

  <Step title="Add to credentials.json">
    ```json theme={null}
    {
      "gemini": {
        "apiKey": "AIza..."
      }
    }
    ```
  </Step>
</Steps>

### When to Use Gemini

<Tabs>
  <Tab title="Benefits">
    * **Free tier** - Generous free quota for testing
    * **Long context** - Up to 1M tokens context window
    * **Multimodal** - Native image and video understanding
    * **Cost-effective** - Generally cheaper than GPT-4
  </Tab>

  <Tab title="Limitations">
    * Less refined for creative writing
    * Fewer integrations
    * Newer platform (fewer examples online)
  </Tab>
</Tabs>

### Fallback Configuration

The system automatically uses Gemini as fallback if OpenAI fails:

```javascript theme={null}
try {
  // Try OpenAI first
  content = await generateWithOpenAI(prompt);
} catch (error) {
  // Fallback to Gemini
  if (credentials.gemini) {
    content = await generateWithGemini(prompt);
  }
}
```

***

## Azure Speech Services

Azure provides high-quality neural voices for text-to-speech.

<Steps>
  <Step title="Create Azure Account">
    Sign up at [Azure Portal](https://portal.azure.com/)
  </Step>

  <Step title="Create Speech Service">
    1. Click "Create a resource"
    2. Search for "Speech"
    3. Select your region (e.g., `eastus`)
    4. Choose pricing tier:
       * **F0** (Free): 5M characters/month
       * **S0** (Standard): Pay-as-you-go
  </Step>

  <Step title="Get Credentials">
    Navigate to "Keys and Endpoint" and copy:

    * Key 1 (subscription key)
    * Region
  </Step>

  <Step title="Configure">
    ```json theme={null}
    {
      "azureSpeech": {
        "subscriptionKey": "your_key",
        "region": "eastus",
        "voice": "en-US-JennyNeural"
      }
    }
    ```

    Or use environment variables:

    ```bash theme={null}
    AZURE_SPEECH_KEY=your_subscription_key
    AZURE_SPEECH_REGION=eastus
    TTS_VOICE=en-US-JennyNeural
    ```
  </Step>
</Steps>

### Voice Selection

Azure offers premium neural voices:

<Accordion title="Female Voices">
  | Voice                | Characteristics        | Best For                   |
  | -------------------- | ---------------------- | -------------------------- |
  | `en-US-JennyNeural`  | Friendly, professional | General content, tutorials |
  | `en-US-AriaNeural`   | Clear, expressive      | News, informative content  |
  | `en-US-AmberNeural`  | Warm, conversational   | Stories, personal vlogs    |
  | `en-US-AshleyNeural` | Young, energetic       | Tech, gaming content       |
  | `en-US-SaraNeural`   | Soft, storytelling     | Narration, bedtime stories |
</Accordion>

<Accordion title="Male Voices">
  | Voice                | Characteristics             | Best For            |
  | -------------------- | --------------------------- | ------------------- |
  | `en-US-GuyNeural`    | Professional, authoritative | Business, education |
  | `en-US-DavisNeural`  | Clear, trustworthy          | News, documentaries |
  | `en-US-TonyNeural`   | News-anchor style           | Formal content      |
  | `en-US-BrianNeural`  | Friendly, approachable      | Tutorials, how-tos  |
  | `en-US-AndrewNeural` | Warm, mature                | Storytelling        |
</Accordion>

### TTS Priority

The system uses this priority order for TTS:

1. **ElevenLabs** (if configured) - Highest quality
2. **Azure Speech** (if configured) - High quality neural voices
3. **OpenAI TTS** (fallback) - Good quality, always available

***

## ElevenLabs Configuration

ElevenLabs offers premium, ultra-realistic voice generation.

<Steps>
  <Step title="Sign Up">
    Create account at [ElevenLabs](https://elevenlabs.io/)
  </Step>

  <Step title="Choose Plan">
    * **Free**: 10,000 characters/month
    * **Starter**: \$5/month - 30,000 characters
    * **Creator**: \$22/month - 100,000 characters
    * **Pro**: \$99/month - 500,000 characters
  </Step>

  <Step title="Get API Key">
    1. Go to [Profile Settings](https://elevenlabs.io/profile)
    2. Copy your API key
  </Step>

  <Step title="Select Voice">
    1. Browse [Voice Library](https://elevenlabs.io/voice-library)
    2. Choose a voice
    3. Copy the Voice ID
  </Step>

  <Step title="Configure">
    ```json theme={null}
    {
      "elevenLabs": {
        "apiKey": "your_api_key",
        "voiceId": "your_voice_id"
      }
    }
    ```

    Or:

    ```bash theme={null}
    ELEVENLABS_API_KEY=your_api_key
    ELEVENLABS_VOICE_ID=your_voice_id
    ```
  </Step>
</Steps>

<Note>
  ElevenLabs provides the most natural-sounding voices and is recommended for premium channels focused on high production quality.
</Note>

***

## Replicate Configuration

Replicate provides access to advanced AI models including Stable Video Diffusion.

<Steps>
  <Step title="Create Account">
    Sign up at [Replicate](https://replicate.com/)
  </Step>

  <Step title="Get API Token">
    1. Go to [API Tokens](https://replicate.com/account/api-tokens)
    2. Create a new token
    3. Copy it (starts with `r8_`)
  </Step>

  <Step title="Add to Configuration">
    ```json theme={null}
    {
      "replicate": {
        "apiKey": "r8_..."
      }
    }
    ```

    Or:

    ```bash theme={null}
    REPLICATE_API_KEY=r8_...
    ```
  </Step>
</Steps>

### Models Used

The system uses:

* **Stable Video Diffusion** - Convert images to video clips
* **Custom video generation models** - For animated content

<Warning>
  Replicate charges per prediction. Video generation can be expensive. Monitor your usage carefully.
</Warning>

***

## Testing Your Configuration

After configuring AI providers, test the connections:

```bash theme={null}
npm run credentials:setup
```

This will:

1. Validate all API keys
2. Test connections to each service
3. Report any configuration issues

### Manual Testing

Test individual services:

<Tabs>
  <Tab title="OpenAI">
    ```javascript theme={null}
    const { Configuration, OpenAIApi } = require('openai');
    const config = new Configuration({
      apiKey: process.env.OPENAI_API_KEY
    });
    const openai = new OpenAIApi(config);

    // Test
    await openai.listModels();
    console.log('✅ OpenAI connected');
    ```
  </Tab>

  <Tab title="Azure Speech">
    ```javascript theme={null}
    const sdk = require('microsoft-cognitiveservices-speech-sdk');
    const speechConfig = sdk.SpeechConfig.fromSubscription(
      process.env.AZURE_SPEECH_KEY,
      process.env.AZURE_SPEECH_REGION
    );
    console.log('✅ Azure Speech configured');
    ```
  </Tab>

  <Tab title="ElevenLabs">
    ```bash theme={null}
    curl -X GET "https://api.elevenlabs.io/v1/voices" \
      -H "xi-api-key: YOUR_API_KEY"
    ```
  </Tab>
</Tabs>

***

## Cost Optimization

Tips for managing AI service costs:

<Accordion title="Use GPT-3.5 for Simple Tasks">
  Configure different models for different agent types:

  ```json theme={null}
  {
    "agents": {
      "strategy": "gpt-4-turbo-preview",
      "script": "gpt-4-turbo-preview",
      "seo": "gpt-3.5-turbo",
      "production": "gpt-3.5-turbo"
    }
  }
  ```
</Accordion>

<Accordion title="Cache Generated Content">
  The system automatically caches:

  * Generated scripts
  * Visual assets
  * Audio files

  Reuse when possible to avoid regeneration costs.
</Accordion>

<Accordion title="Set Usage Limits">
  Configure limits in each provider's dashboard:

  * OpenAI: Set monthly spending limits
  * Azure: Use free tier for testing
  * ElevenLabs: Choose appropriate plan
  * Replicate: Monitor per-prediction costs
</Accordion>

<Accordion title="Monitor Usage">
  Enable analytics to track AI costs:

  ```bash theme={null}
  ENABLE_ANALYTICS=true
  ```

  View cost reports at `/analytics/ai-costs`
</Accordion>

***

## Best Practices

<CardGroup cols={2}>
  <Card title="Use Environment-Specific Keys" icon="key">
    Use different API keys for development and production to separate usage tracking.
  </Card>

  <Card title="Enable Fallbacks" icon="shield">
    Configure multiple providers so the system can continue operating if one fails.
  </Card>

  <Card title="Monitor Quotas" icon="chart-line">
    Regularly check API quotas and usage to avoid service interruptions.
  </Card>

  <Card title="Rotate Keys Periodically" icon="rotate">
    Change API keys every few months for security best practices.
  </Card>
</CardGroup>

## Next Steps

<Card title="YouTube Setup" icon="youtube" href="/configuration/youtube-setup">
  Complete YouTube API configuration and authentication
</Card>
