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

# nx:genai

> Generate AI video or image assets at render time and inject them directly into your After Effects composition

The `nx:genai` function calls an external AI media generation provider during the render pipeline and injects the result into a specified layer before After Effects starts compositing. This lets you combine AI-generated content with your AE templates in a single job - no manual steps, no intermediate storage wrangling.

The provider is called at render time, so the generated asset is always fresh and unique to each job.

## Parameters

<ParamField path="provider" type="string" required>
  The AI provider to call. Currently supported: `fal`
</ParamField>

<ParamField path="key" type="string" required>
  API key for the provider. Use a [secret reference](/docs/cloud/jobs/secrets) to avoid embedding credentials directly - e.g. `${secret.FAL_KEY}`
</ParamField>

<ParamField path="model" type="string" required>
  The model identifier on the provider's platform. The exact value depends on which model you want to use - refer to your provider's model library for available options.
</ParamField>

<ParamField path="type" type="string" required>
  Output type: `video` or `image`. Determines how the result is injected into the layer.
</ParamField>

<ParamField path="layerName" type="string" required>
  The footage layer in your After Effects composition where the generated asset will be placed.
</ParamField>

<ParamField path="data" type="object" required>
  Model-specific parameters passed directly to the provider's API. The shape of this object varies by model - refer to your provider's documentation for the full list of available fields.
</ParamField>

## Example

The following example uses FAL.AI to generate a talking-head video of a character speaking a provided script, then injects it into a footage layer:

```json theme={null}
{
  "type": "function",
  "name": "nx:genai",
  "params": {
    "provider": "fal",
    "key": "${secret.FAL_KEY}",
    "model": "infinitalk/single-text",
    "type": "video",
    "layerName": "var_video",
    "data": {
      "image_url": "https://example.com/character.jpg",
      "text_input": "A Victorian inventor journeys to the distant future, encountering the peaceful Eloi and the subterranean Morlocks.",
      "voice": "Eric",
      "prompt": "A young man with a beard records audio with a microphone. He appears engaged and expressive, suggesting a podcast or voiceover.",
      "num_frames": 721,
      "resolution": "720p",
      "acceleration": "high"
    }
  }
}
```

The `data` fields here are specific to the `infinitalk/single-text` model - a different model would expect a different set of parameters. Always consult the model's documentation on the provider platform for the exact payload shape.

## Adaptive Composition Duration

Since AI-generated videos have variable lengths, use [`nx:layer-duration-set`](/docs/cloud/jobs/functions/nx-layer-duration-set) immediately after `nx:genai` in your `assets` array to automatically adjust the layer and composition duration to match the generated output:

```json theme={null}
{
  "type": "function",
  "name": "nx:layer-duration-set",
  "params": {
    "layerName": "var_video"
  }
}
```

## Storing Your Provider Key as a Secret

Never embed provider API keys directly in a job payload. Store them as Nexrender secrets and reference them with the `${secret.NAME}` syntax - see [Secrets Management](/docs/cloud/jobs/secrets) for details.
