> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hoox.video/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Script

> Generate a video script from a prompt with cost estimation

## Overview

This endpoint generates a video script from a text prompt. It's useful for getting an accurate cost estimate before committing to full video generation, and for reviewing/editing the script before proceeding.

## Authentication

<Info>
  This endpoint requires API key authentication and consumes credits from your account.
</Info>

## Request Body

<ParamField body="prompt" type="string" required>
  Text prompt describing the video content (max 10,000 characters).
</ParamField>

<ParamField body="duration" type="number" default="60">
  Target video duration in seconds (10-600).
</ParamField>

<ParamField body="urls" type="array">
  Array of web URLs to extract content from (max 10).
</ParamField>

<ParamField body="webSearch" type="boolean" default="false">
  Enable web search to find additional relevant content.
</ParamField>

## Response

<ResponseField name="script" type="string">
  The generated video script.
</ResponseField>

<ResponseField name="cost" type="number">
  Credits consumed for script generation.
</ResponseField>

<ResponseField name="extractedImages" type="array">
  Array of image URLs extracted from web sources (strings).
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://app.hoox.video/api/public/v1/script/generate" \
    -H "Authorization: Bearer your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "prompt": "Create an educational video about renewable energy sources, focusing on solar and wind power",
      "duration": 90,
      "webSearch": true,
      "urls": ["https://www.energy.gov/renewable-energy"]
    }'
  ```

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

  url = "https://app.hoox.video/api/public/v1/script/generate"
  headers = {
      "Authorization": "Bearer your_api_key",
      "Content-Type": "application/json"
  }

  data = {
      "prompt": "Create an educational video about renewable energy sources, focusing on solar and wind power",
      "duration": 90,
      "webSearch": True,
      "urls": ["https://www.energy.gov/renewable-energy"]
  }

  response = requests.post(url, headers=headers, json=data)
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://app.hoox.video/api/public/v1/script/generate', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer your_api_key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      prompt: "Create an educational video about renewable energy sources, focusing on solar and wind power",
      duration: 90,
      webSearch: true,
      urls: ["https://www.energy.gov/renewable-energy"]
    })
  });

  const data = await response.json();
  console.log(data);
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "script": "In today's world, renewable energy has become more crucial than ever. Let's explore two of the most promising sources: solar and wind power.\n\nSolar energy harnesses the power of the sun through photovoltaic panels. These panels convert sunlight directly into electricity, providing a clean and abundant energy source. The technology has advanced significantly, making solar power more affordable and efficient than ever before.\n\nWind power, on the other hand, captures the kinetic energy of moving air through wind turbines. These towering structures can generate substantial amounts of electricity, especially in areas with consistent wind patterns.\n\nBoth technologies offer significant environmental benefits, reducing our dependence on fossil fuels and helping combat climate change. As we move forward, these renewable sources will play an increasingly important role in our energy future.",
    "cost": 15,
    "extractedImages": [
      "https://example.com/solar-panels.jpg",
      "https://example.com/wind-turbines.jpg",
      "https://example.com/renewable-energy-chart.png"
    ]
  }
  ```

  ```json Error 400 - Validation Failed theme={null}
  {
    "error": "Validation failed",
    "details": [
      {
        "code": "MISSING_FIELD",
        "message": "Prompt is required",
        "field": "prompt"
      }
    ]
  }
  ```

  ```json Error 402 - Insufficient Credits theme={null}
  {
    "error": "Insufficient credits. Required: 15, Available: 8",
    "code": "INSUFFICIENT_CREDITS"
  }
  ```
</ResponseExample>

## Credit Costs

Script generation costs are based on:

* **Base cost**: 0.1 credits every 60 seconds
* **Web search**: +0.1 credits when enabled
* **URL processing**: +0.1 credits per URL

<Tip>
  Script generation costs are separate from video generation costs.
</Tip>

## Usage Tips

### 1. Content Enhancement

* Use `webSearch: true` to find relevant, up-to-date information
* Provide specific URLs to extract content from predefined pages (like product page or article)
* Review extracted images to see what visual content was found

### 2. Script Customization

* Edit the generated script before using it in video generation
* Adjust prompt to match your brand voice and pacing
* Add specific product mentions or calls-to-action

## Error Codes

* `MISSING_FIELD`: Prompt is required
* `INVALID_TYPE`: Invalid parameter type
* `INVALID_VALUE`: Parameter value out of allowed range
* `INSUFFICIENT_CREDITS`: Not enough credits for script generation
* `SCRIPT_GENERATION_FAILED`: Failed to generate script

## Next Steps

After generating a script:

1. **Review and Edit**: Modify the script to match your needs
2. **Choose Resources**: Use `/voice/list` and `/avatar/list` to select voice and avatar
3. **Generate Video**: Use the script in `/generation/start` endpoint
4. **Monitor Progress**: Check status with `/generation/status/{job_id}`
5. **Export Video**: Use `/export/start` endpoint to export the video in the desired format
6. **Monitor Export Progress**: Check status with `/export/status/{job_id}`
