Skip to content

feat: add ltx2.h public C API for LTX-2 text-to-video and image-to-video - #48

Open
kamalbuilds wants to merge 3 commits into
tetherto:2026-06-04from
kamalbuilds:feat/ltx2-c-api-pr
Open

kamalbuilds wants to merge 3 commits into
tetherto:2026-06-04from
kamalbuilds:feat/ltx2-c-api-pr

Conversation

@kamalbuilds

Copy link
Copy Markdown

Summary

Adds include/ltx2.h, a small public C API for LTX-2 video generation, so a program can run text-to-video and image-to-video without going through sd-cli:

  • ltx2_new_ctx() / ltx2_free_ctx(): create a context from the diffusion model, VAE, Gemma text encoder and embeddings-connector paths.
  • ltx2_generate_t2v() and ltx2_generate_i2v(): return RGB frames (plus audio when the model produces it).

src/ltx2_api.cpp is a thin wrapper over the existing new_sd_ctx() / generate_video() entry points with LTX-2 defaults (LTX2_SCHEDULER, 8k+1 frame count, 32-aligned dimensions). It adds no new model code and changes no existing behaviour. src/*.cpp is already globbed, so the only build change is listing ltx2.h in SD_PUBLIC_HEADERS.

Related Issue / Discussion

Part of the scope of the Tether bounty "LTX-2 Video Generation, qvac-ext-stable-diffusion.cpp + Bare Addon" (https://tether.dev/grants/bounties/2885262943/), which asks for a C API usable without the CLI. It builds on the LTX-2.3 engine already on 2026-06-04 (#13).

Additional Information

Verified on Apple M3, macOS 26.4.1, Metal build (cmake -DSD_METAL=ON -DCMAKE_BUILD_TYPE=Release):

  • stable-diffusion builds with no errors; ltx2_api.cpp has 0 warnings under -Wall -Wextra.
  • nm libstable-diffusion.a exports ltx2_new_ctx, ltx2_free_ctx, ltx2_generate_t2v, ltx2_generate_i2v.
  • A 27-line C program (kept local per CONTRIBUTING) links against the static library and calls ltx2_new_ctx() with missing model paths. It gets NULL back cleanly: ltx2-capi-smoke: PASS (ltx2_new_ctx rejected missing model files). I confirmed the check fails when inverted.
  • Formatted with the repo .clang-format.

Not verified in this PR: a full generation run through the C API with real LTX-2.3 weights. Happy to add one if you point me at the checkpoint and quant you test with.

Checklist

🤖 Generated with Claude Code

Brings ltx2_new_ctx/ltx2_free_ctx/ltx2_generate_t2v/ltx2_generate_i2v
from feat/ltx2-video-generation. No API drift against the base
stable-diffusion.h: generate_video is already 5-arg with sd_audio_t**,
LTX2_SCHEDULER already exists in scheduler_t, and llm_path already
loads under the text_encoders.llm. prefix this facade relies on.
Same install path as stable-diffusion.h. src/ltx2_api.cpp needs no
CMake change: src/*.cpp is already globbed into SD_LIB_SOURCES.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant