> ## 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.

# Generate Content

> Manually trigger content generation for YouTube videos

## Endpoint

```
POST /generate
```

## Description

Manually triggers the full content generation pipeline, including strategy development, script writing, thumbnail design, SEO optimization, and production processing. The generated content is saved to the database and scheduled for publishing.

## Request Body

<ParamField body="topic" type="string" optional>
  The topic for the video content. If not provided, the Content Strategy Agent will automatically select a trending topic based on analytics and research.
</ParamField>

<ParamField body="style" type="string" optional>
  The style or format for the video. Options depend on your channel configuration.

  Examples: `"tutorial"`, `"vlog"`, `"review"`, `"educational"`
</ParamField>

<ParamField body="length" type="string" optional default="medium">
  Target length for the video content.

  Common values:

  * `"short"` - Short-form content (\< 60 seconds)
  * `"medium"` - Standard content (5-15 minutes)
  * `"long"` - Long-form content (15+ minutes)
</ParamField>

## Response

<ResponseField name="success" type="boolean" required>
  Indicates whether content generation succeeded.
</ResponseField>

<ResponseField name="result" type="object">
  Contains the generated content details.

  <ResponseField name="result.contentId" type="string" required>
    Unique identifier for the generated content. Use this ID with the `/publish/:contentId` endpoint.
  </ResponseField>

  <ResponseField name="result.title" type="string" required>
    The generated video title.
  </ResponseField>

  <ResponseField name="result.scheduledFor" type="string" required>
    ISO 8601 timestamp when the content is scheduled for automatic publishing.
  </ResponseField>
</ResponseField>

<ResponseField name="error" type="string">
  Error message if `success` is `false`.
</ResponseField>

## Example Requests

<CodeGroup>
  ```bash cURL - Auto Topic theme={null}
  curl -X POST http://localhost:3456/generate \
    -H "Content-Type: application/json" \
    -d '{}'
  ```

  ```bash cURL - Specific Topic theme={null}
  curl -X POST http://localhost:3456/generate \
    -H "Content-Type: application/json" \
    -d '{
      "topic": "Advanced React Hooks Tutorial",
      "style": "tutorial",
      "length": "medium"
    }'
  ```

  ```javascript JavaScript (Fetch) theme={null}
  const response = await fetch('http://localhost:3456/generate', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      topic: 'Advanced React Hooks Tutorial',
      style: 'tutorial',
      length: 'medium'
    })
  });

  const result = await response.json();
  console.log(result);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'http://localhost:3456/generate',
      json={
          'topic': 'Advanced React Hooks Tutorial',
          'style': 'tutorial',
          'length': 'medium'
      }
  )

  print(response.json())
  ```
</CodeGroup>

## Example Response

### Success

```json theme={null}
{
  "success": true,
  "result": {
    "contentId": "content_1234567890abcdef",
    "title": "Master React Hooks in 10 Minutes - Complete Guide for Beginners",
    "scheduledFor": "2026-03-06T14:00:00.000Z"
  }
}
```

### Error

```json theme={null}
{
  "success": false,
  "error": "Failed to generate script: API quota exceeded"
}
```

## Response Codes

| Status Code | Description                            |
| ----------- | -------------------------------------- |
| 200         | Content generation successful          |
| 500         | Server error during content generation |

## Generation Pipeline

The `/generate` endpoint executes the following steps:

1. **Content Strategy** - Analyzes trends and generates content strategy
2. **Script Writing** - Creates the video script based on the strategy
3. **Thumbnail Design** - Generates an eye-catching thumbnail
4. **SEO Optimization** - Optimizes title, description, tags, and metadata
5. **Production Processing** - Processes all content for publishing
6. **Database Save** - Stores the content and schedules automatic publishing

<Note>
  Content generation can take 30-90 seconds depending on the complexity and AI model response times. Consider implementing a timeout of at least 120 seconds for this endpoint.
</Note>

## Use Cases

### Manual Content Creation

Generate content on-demand outside the automated schedule:

```bash theme={null}
curl -X POST http://localhost:3456/generate \
  -H "Content-Type: application/json" \
  -d '{"topic": "Breaking News: Latest Tech Updates"}'
```

### Batch Content Generation

Generate multiple pieces of content programmatically:

```javascript theme={null}
const topics = [
  'Introduction to Machine Learning',
  'Web Development Best Practices',
  'Cloud Computing Basics'
];

for (const topic of topics) {
  const response = await fetch('http://localhost:3456/generate', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ topic, length: 'medium' })
  });
  
  const result = await response.json();
  console.log(`Generated: ${result.result.title}`);
}
```

## Error Handling

Common errors and their causes:

| Error Message         | Cause                           | Solution                                 |
| --------------------- | ------------------------------- | ---------------------------------------- |
| API quota exceeded    | External API limits reached     | Wait for quota reset or upgrade API plan |
| Invalid credentials   | YouTube API credentials missing | Run `npm run credentials:setup`          |
| Database error        | Database connection failed      | Check database configuration             |
| Agent not initialized | System still starting up        | Wait for initialization to complete      |
