Skip to content

feat(tools): add TextToVideo tool for gateway video generation with lip-synced avatars - #1270

Merged
edenreich merged 16 commits into
mainfrom
fix/issue-1257
Sep 23, 2026
Merged

edenreich merged 16 commits into
mainfrom
fix/issue-1257

Conversation

@inference-gateway-maintainer

@inference-gateway-maintainer inference-gateway-maintainer Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #1257
Resolves #1271
Resolves #1272

Summary

Adds the TextToVideo agent tool. It renders a video clip through the gateway's Videos API (POST /v1/videos, GET /v1/videos/{id}, GET /v1/videos/{id}/content, gateway v0.54+). Given a portrait plus an audio clip, it renders a lip-synced talking clip instead. The tool follows the TextToSFX/TextToMusic template:

  • opt-in text_to_video config, off by default because avatar renders send the user's face and voice to a third-party provider
  • a VideoService domain port with a gateway infrastructure implementation
  • async-job polling hidden from the agent
  • MP4 output confined to text_to_video.output_dir

On top of that, the PR ships the avatar library, which also feeds prompt renders as reference_images (#1272), and a CreateAvatar tool (#1271).

Changes

  • SDK: bumped to v1.39.0 (schemas v0.31.0), which adds CreateVideoRequest.ReferenceImages.
  • Config: new top-level text_to_video section with enabled, model, avatar_model, size, output_dir, timeout, poll_interval, create_avatar and require_approval.
    • The two models swap independently. model (default elevenlabs/veo-3.1-fast-generate-001) renders prompts and first-frame shots. avatar_model (default elevenlabs/creatify-aurora) renders lip-sync clips.
    • VideoRequest.IsAvatar() picks between them, using the gateway's own rule: audio present means an avatar render.
    • Validation checks both models are provider/model ids and rejects a negative timeout or poll_interval.
    • INFER_TEXT_TO_VIDEO_* overrides come from the reflective loader.
  • Gateway manager: a gateway the CLI starts gets VIDEOS_ENABLED=true while the tool is enabled. The gateway only serves /v1/videos with that flag.
  • Domain / infrastructure: VideoService port with a VideoRequest value. internal/agent/infrastructure/video_service.go does the rest:
    • builds the multipart body
    • rejects a body (avatar images plus audio) over the gateway's 10 MiB limit before sending
    • polls RetrieveVideo under the timeout-bounded context
    • surfaces the provider's error.message
    • downloads the content with DownloadVideoContent
  • Avatar library (internal/avatars): each avatar is a folder ~/.infer/avatars/<name>/ holding one or more portrait images, such as several angles.
    • A lip-sync render sends the first image in sort order as input_reference.
    • A prompt render (no audio) with a library avatar sends every image as reference_images ([FEATURE] Send avatar folder extra images as reference_images #1272), so model keeps the person consistent. It sends no input_reference then: the gateway rejects the two together (feat(videos): map reference_images to elevenlabs images inference-gateway#689), so this departs from the issue's "remaining images" wording.
    • Per-model image limits stay in the gateway (Veo 3, Seedance 9-30). Its 400 names the limit and reaches the agent verbatim.
    • A bare .png/.jpg/.jpeg/.webp file name still resolves in the working directory for one-off portraits, and stays the first frame.
    • An unknown avatar name fails with the list of available avatars, so the agent can recover.
    • /reset does not touch the library.
  • Photo normalisation: avatars.Create decodes a JPEG, applies its EXIF orientation and re-encodes it.
    • Phone photos stored sideways arrive upright.
    • Camera and GPS metadata never reach the library or a provider.
    • Angles are generated from the stored front image, not the caller's original file.
    • PNG/WebP pass through.
    • Stdlib only: a small EXIF Orientation reader plus the 8-way transform.
  • Commands: infer avatars create <name> --from <photo>, infer avatars list [--format json] and infer avatars delete <name>. The desktop uses these instead of re-implementing them ([FEATURE] Avatars: record once, reuse a talking avatar in Content projects desktop#311).
    • create stores the photo as 01-front and generates extra views in parallel through the gateway's image edit API with tools.image_edit.model (default openai/gpt-image-2).
    • The default views are both three-quarter angles; left/right profiles are available on request, and --angles "" only copies the photo.
    • --quality defaults to high and --size to 1024x1536 (portrait); both pass through to the provider.
    • It never overwrites an existing avatar, a failed view removes the half-built folder, and the gateway starts only after the name, photo and angles pass validation.
    • Generating views sends the photo to the image-edit provider (OpenAI by default).
  • CreateAvatar tool ([FEATURE] CreateAvatar tool: let the agent build an avatar from a photo #1271): internal/agent/tools/create_avatar.go, a thin wrapper over avatars.Create. It covers generated portraits, selfies sent over a channel and Content projects.
    • Registered only when text_to_video.enabled and text_to_video.create_avatar are both true.
    • Requires approval by default; text_to_video.require_approval overrides.
    • photo is a bare file name resolved in the sandboxed working directory, then the session's artifacts directory, via the shared resolveMediaInputPath.
    • It never overwrites and has no delete counterpart.
  • TextToVideo tool (internal/agent/tools/text_to_video.go): inputs are prompt, seconds, size, avatar, audio and output_path, validated as [FEATURE] TextToVideo tool: generate a video clip, optionally lip-synced from a portrait and an audio clip, through the gateway #1257 requires. Input lookups share resolveMediaInputPath, extracted from TextToSpeech.
  • Tests:
    • Tool: text-only render, a library avatar to its primary image with audio and to every image as references without audio, a file portrait staying the first frame, validation, cleanup on failure, registry gating.
    • Service: poll lifecycle, multipart files, repeated reference parts, the upload limit counting references, failed-job message, timeout, and model vs avatar_model selection.
    • CreateAvatar: validation table, artifacts-dir fallback, no provider call for an existing name or angles: [], image edit disabled, registry gating, approval default.
    • internal/avatars: list, get, delete and create (including traversal names), EXIF parsing in both byte orders, all 8 orientations, and a sideways photo stored upright without metadata.
    • Config: model resolution and validation.
    • Integration: the full agent loop against a mock Videos API.
    • Also fixes newEnvWithScenarios, which had dropped the mock-gateway handle.
  • Docs: docs/text-to-video.md (models, avatar library, reference images, CreateAvatar, gateway requirements), tools-reference.md, configuration-reference.md, directory-structure.md and README.

Avatars and ElevenLabs

ElevenLabs has no public avatar API yet ("planned for future release"), and /v1/flows/video has no avatar id. This PR inlines the images as base64 on each render, so nothing is created at the provider that could be listed or deleted. The only avatars are the local folders managed by infer avatars. ElevenLabs' Assets API (/v1/assets upload/list/delete) would allow upload-once-reference-by-id, but that needs schemas, gateway and SDK work first.

Cross-repo impact

Verification

  • task precommit:run passes: mod:tidy, mocks, fmt, lint:imports, golangci-lint (0 issues), markdownlint.
  • task test passes, and go test -race passes on internal/avatars, internal/agent/tools, internal/agent/infrastructure and config.
  • Live run against the managed gateway, which auto-updated to v0.55.0, with an iPhone photo (3088x2316 pixels, EXIF Orientation 6, GPS data):
    • infer avatars create --angles "" stored 01-front.jpeg upright at 2316x3088 with no EXIF/GPS, in 0.3 s.
    • infer avatars create with the default angles on v0.55.0 got a 400 unsupported_file_mimetype from OpenAI (after a key refresh), and the half-built folder was removed.
    • TextToSpeech "hello world, this is a test" → 1.5 s WAV.
    • TextToVideo lip-sync with that WAV returned a 422 Input should be 'audio/mpeg' or 'audio/wav', input audio/wave, which is [DOCS] Fix docs/ drift found by README-to-codebase audit (phantom refs, broken links, stale config) #686. With an ID3-tagged MP3 it passed validation and got a 402 paid_plan_required ("This endpoint requires a Pro plan or above") from ElevenLabs.
    • TextToVideo reference render (veo-3.1-fast) with the library avatar reached ElevenLabs and got the same 402, so the gateway accepted the reference_images-only body. A 4-image avatar got the gateway's model "veo-3.1-fast-generate-001" accepts at most 3 'reference_images', got 4, which confirms the repeated parts arrive and are parsed.
    • No MP4 has been rendered yet: that needs an ElevenLabs Pro plan on the gateway's key.
    • CreateAvatar via infer tools execute:
      • not registered without create_avatar
      • approval_required: true by default
      • ../ and absolute photo paths rejected
      • angles: [] created the avatar with the photo stored upright
      • an existing name refused
      • a default-angles call during the key outage failed cleanly and left no folder
  • CodeQL go/path-injection alerts on the avatar name are fixed (inline guard plus filepath.Base).

…ip-synced avatars

Renders a video clip through the gateway's unified Videos API (POST /v1/videos, GET /v1/videos/{id}, GET /v1/videos/{id}/content) behind an opt-in text_to_video config section, defaulting to elevenlabs/creatify-aurora. Avatar plus audio renders lip-sync a portrait to a .wav or .mp3 clip; text-only renders take prompt, seconds and size passthroughs. The service polls the async job every poll_interval until completed or failed and downloads the MP4 content into text_to_video.output_dir; combined avatar plus audio uploads over the gateway's 10 MiB body limit are rejected before sending.
edenreich and others added 6 commits September 22, 2026 23:05
…oVideo

The gateway serves /v1/videos only with VIDEOS_ENABLED=true, so a
CLI-started gateway answered every TextToVideo render with a 404. Set it
next to IMAGES_ENABLED for both the container and the binary.
newEnvWithScenarios lost env.gateway when newEnvWithHandler was split
out, so every test asserting on gateway requests hit a nil pointer.
…ideo

- text_to_video.model (default elevenlabs/veo-3.1-fast-generate-001)
  renders prompts; text_to_video.avatar_model (default
  elevenlabs/creatify-aurora) renders lip-synced clips. The default model
  used to be the avatar-only creatify-aurora, so text-only prompts failed.
- Avatars are folders under ~/.infer/avatars/<name>/ holding one or more
  portrait images; lip-sync models get the first in sort order. A bare
  image file name still resolves in the working directory.
- infer avatars list [--format json] and infer avatars delete <name>.
- An unknown avatar name fails with the list of available avatars.
- Config validation rejects a negative timeout or poll_interval.
Comment thread internal/avatars/avatars.go Fixed
…system

CodeQL (go/path-injection) could not see through the validName helper, so
the tool-argument avatar name reached os.ReadDir and, via the primary
image path, os.ReadFile as tainted. Check the name inline in Get, join
with filepath.Base(name), and let Delete remove the sanitized name Get
returns. Also reject "." explicitly so delete can never target the
library root.
…hoto

infer avatars create <name> --from <photo> copies the photo in as the
primary 01-front image and generates the requested views (default: both
three-quarter views; left/right profiles on request) in parallel through
the gateway's image edit API with tools.image_edit.model. --quality
(default high) and --size (default 1024x1536 portrait) pass through to
the provider. An existing avatar is never overwritten, a failed view
removes the half-built folder, and the gateway only starts once the
name, photo and angles are validated.
Comment thread cmd/avatars/avatars.go Resolved
…rs (#1272)

A library avatar in a TextToVideo render without audio now sends every image in its folder as reference_images, so the prompt model keeps the person consistent. Lip-sync renders and one-off image files keep the single input_reference. The gateway rejects the two together, so reference renders send no input_reference at all. The 10 MiB body check counts the reference images.
Phone photos are often stored sideways with an EXIF Orientation tag, and carry camera and GPS metadata. avatars.Create now decodes a JPEG, applies its orientation and re-encodes it, so the library and every provider get an upright image without metadata. Angles are now edited from the stored front image instead of the caller's original file.
CreateAvatar lets the agent build a library avatar from a photo, over the same avatars.Create as infer avatars create: a generated portrait, a selfie sent over a channel, or a Content project's presenter. It is registered only when text_to_video.enabled and the new text_to_video.create_avatar opt-in are both true, and requires approval unless text_to_video.require_approval is set. The photo is a bare file name resolved in the sandboxed working directory, then the session's artifacts directory. It never overwrites, and there is no delete tool.
Comment thread internal/avatars/avatars.go Fixed
CodeQL flagged go/path-injection: the CreateAvatar tool's angles argument reached the generated file name through fmt.Sprintf. Unknown angles were already rejected, but the name was still built from caller input. avatars.Create now swaps each requested angle for the matching Angles key, so file names come only from the library's own angle names.
@inference-gateway-maintainer inference-gateway-maintainer Bot moved this to Todo in 2026 Sep 23, 2026
@edenreich
edenreich merged commit bcadcbc into main Sep 23, 2026
1 check passed
@edenreich
edenreich deleted the fix/issue-1257 branch September 23, 2026 13:27
@edenreich edenreich moved this from Todo to Done in 2026 Sep 23, 2026
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.206.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

No open projects
Status: Done

2 participants