API / add-spoken-dialogue-with-reference-audios

API

Add spoken dialogue with reference_audios on Imagine video

Add spoken dialogue with reference_audios on Imagine video

On grok-imagine-video-1.5, reference-to-video can carry a voice through reference_audios. Preset voices come from the same built-in roster as Text to Speech (for example eve, leo). Identifiers are case-insensitive. Max 3 voices per request. Tag them in the prompt as <AUDIO_0>, <AUDIO_1>, <AUDIO_2> (and keep <IMAGE_n> tags when you also pass reference images).

Generated videos include an audio track by default. Pass generate_audio=false when you need a silent plate. Custom voice files (your own audio as a voice reference) are limited to trusted partners on request; the public path is preset voice_id values.

Dialogue with stills and two voices

REQUEST_ID=$(curl -s -X POST https://api.x.ai/v1/videos/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d '{
    "model": "grok-imagine-video-1.5",
    "prompt": "The person from <IMAGE_1> presents the product from <IMAGE_2> on the set from <IMAGE_3>, speaking with the voice from <AUDIO_0>. A second speaker with the voice from <AUDIO_1> replies.",
    "reference_images": [
      {"url": "<IMAGE_URL_1>"},
      {"url": "<IMAGE_URL_2>"},
      {"url": "<IMAGE_URL_3>"}
    ],
    "reference_audios": [
      {"voice_id": "eve"},
      {"voice_id": "leo"}
    ],
    "duration": 8,
    "aspect_ratio": "9:16",
    "resolution": "720p"
  }' | jq -r '.request_id')

Poll GET /v1/videos/{request_id} until status is done, then read video.url. Reference-to-video resolution is capped at 720p. Duration 1–15 seconds.

Python SDK shape:

import os
import xai_sdk

client = xai_sdk.Client(api_key=os.getenv("XAI_API_KEY"))

response = client.video.generate(
    prompt="The person from <IMAGE_1> presents the product from <IMAGE_2>, speaking with the voice from <AUDIO_0>.",
    model="grok-imagine-video-1.5",
    reference_image_urls=["<IMAGE_URL_1>", "<IMAGE_URL_2>", "<IMAGE_URL_3>"],
    reference_audios=[{"voice_id": "eve"}, {"voice_id": "leo"}],
    duration=8,
    aspect_ratio="9:16",
    resolution="720p",
)
print(response.url)

An unknown voice_id returns 400 with the list of available voices. You can use reference_audios alone or with reference_images. Do not mix image (image-to-video first frame) with reference_images in one request.

Pitfalls

  • This is the API path. Consumer Imagine on grok.com / iOS / Android may expose different controls; do not paste reference_audios JSON into the consumer box.
  • For image-locked opening frames, use Animate image-to-video with the Imagine API. Reference-to-video guides people and objects without locking the first frame.
  • For still-only reference images without dialogue, see Generate a video from reference images.