Skip to main content

Crate agentai_video

Crate agentai_video 

Source
Expand description

§AgentAI Video

Video generation for AgentAI. Video APIs are asynchronous: VideoProvider::submit sends a request and returns a VideoJob, which you follow with VideoProvider::status and, when it is JobStatus::Completed, fetch with VideoProvider::download. Polling is up to the caller.

use std::time::Duration;
use agentai_video::{JobStatus, VideoRequest, from_model};

// The provider comes from the prefix of the model name, its settings from environment
// variables (`COMFY_SERVE_BASE_URL` here)
let provider = from_model("comfy-serve::wan-2.2")?;
let job = provider
    .submit(VideoRequest::new("A lighthouse at dawn").with_duration(5))
    .await?;
loop {
    match provider.status(&job).await? {
        JobStatus::Completed => break,
        JobStatus::Failed(message) => return Err(message.into()),
        JobStatus::Gone => return Err("the job is gone".into()),
        _ => tokio::time::sleep(Duration::from_secs(5)).await,
    }
}
let video = provider.download(&job).await?; // a `Media`, base64 or a URL

A VideoJob can be stored (serde) and given back, possibly to a new provider, after a restart: status, download and cancel need no model. A job does not record which provider made it, so store the provider and model name next to it.

§Inputs

VideoRequest::with_inputs takes VideoInputs, one of three modes:

  • None (the default): text-to-video.
  • Frames { first, last }: image-to-video, from a first frame, a last frame or both.
  • References(VideoReferences): reference-to-video, from reference images, videos and audio.

Frames and references exclude each other. A provider that cannot send some input returns VideoError::Unsupported. Options you do not set (duration, resolution, aspect ratio, seed) are not sent, and values are not checked here: the API reports the ones it does not accept.

§Models

list_models (or VideoProvider::list_models) returns VideoModels with the durations, resolutions, aspect ratios and input kinds a model accepts, where the provider says so. None in one of these lists means the provider does not say, not that the option is unsupported: offer it and let the server answer. Some(vec![]) means there is nothing to choose.

§Providers

PrefixSettingsCancelInputs
comfy-serveCOMFY_SERVE_BASE_URL (required), COMFY_SERVE_API_KEY (optional)yesfirst and last frames; image, video and audio references; files are uploaded as multipart
openrouterOPENROUTER_API_KEY (required), OPENROUTER_BASE_URL (optional)nofirst and last frames and image references, sent as URLs or data URLs

To set the key and base URL in code, or to change timeouts or the proxy, build the provider yourself and give it your own client:

ⓘ
// `reqwest::Client` needs `reqwest` in your dependencies; `ReqwestClient` and the other HTTP
// types are re-exported from this crate
use agentai_video::ReqwestClient;
use agentai_video::provider::comfy_serve::ComfyServeVideoProvider;

let client = reqwest::Client::builder().build().unwrap();
let provider = ComfyServeVideoProvider::new("wan-2.2", "", "http://localhost:8000")
    .with_http_client(ReqwestClient::from_client(client));

The HTTP types (HttpClient, HttpRequest, HttpResponse, HttpError, ReqwestClient), Media and mime are re-exported, so this crate is enough to use a provider with your own client or to implement VideoProvider for another API.

§Files

mime::from_path guesses the type of an input file from its name, and Media::extension gives the file extension of a downloaded video’s type:

let path = "first.jpg";
let first = Media::from_bytes(mime::from_path(path).ok_or("unknown type")?, std::fs::read(path)?);
let request = VideoRequest::new("The scene comes alive").with_inputs(VideoInputs::Frames {
    first: Some(first),
    last: None,
});
// ... submit, poll, download ...
let bytes = video.bytes(&ReqwestClient::new()).await?;
std::fs::write(format!("video.{}", video.extension()), bytes)?;

§Limits

  • Files travel in memory as Media (base64 or a URL), so large videos are held whole.
  • There is no waiting helper (the loop above is yours to write, with your timing and your runtime), no retries and no timeouts of its own.
  • There are no agent tools: this crate does not depend on agentai.

§Features

Available features for agentai-video crate.

Features list:

  • rustls-ring (enabled by default) — TLS with rustls and the ring crypto provider, checking certificates against the OS trust store.
  • rustls-aws-lc — TLS with rustls and the aws-lc-rs crypto provider (builds the aws-lc-sys C library).
  • native-tls — TLS of the operating system (OpenSSL, SChannel or Security Framework). It cannot be combined with a rustls-* feature: set default-features = false.
  • system-proxy (enabled by default) — Reads the macOS and Windows system proxy settings.

Re-exports§

pub use provider::JobStatus;
pub use provider::VideoError;
pub use provider::VideoInputKind;
pub use provider::VideoInputs;
pub use provider::VideoJob;
pub use provider::VideoModel;
pub use provider::VideoProvider;
pub use provider::VideoReferences;
pub use provider::VideoRequest;
pub use provider::from_model;
pub use provider::list_models;

Modules§

mime
MIME types and file extensions of images, audio and video.
provider
Video providers

Structs§

HttpRequest
A request sent with a HttpClient. The body is always plain bytes, so a client only has to send them.
HttpResponse
A response returned by a HttpClient, with the whole body read.
Media
An image, audio or other file in a message.
ReqwestClient
HttpClient on top of reqwest.

Enums§

HttpError
Errors of a HttpClient and of building or reading a request.
MediaSource
Where the bytes of Media are.

Traits§

HttpClient
Sends HTTP requests.