AI Video Generation Dart SDK
Typed, null-safe client for launching and monitoring video generation jobs across OpenAI Sora 2, Google Vertex Veo, ByteDance JiMeng, Kwai Kling, and Alibaba WanXiang. Each provider has its own generator class; you can use them directly or with the lightweight polling helper. Local image paths can auto-convert to base64 where supported.
Installation
dart pub add ai_video_gen_dart
Copy .env.example to .env (or export these vars) before running the examples:
SORA2_API_KEY=sk-...
SORA_BASE_URL=https://api.openai.com
VEO_OAUTH_TOKEN=ya29....
VEO_LOCATION=us-central1
VEO_PROJECT_ID=your-project-id
VEO_MODEL=veo-3.1-generate-001
VEO_BASE_URL=
VEO_STORAGE_URI=gs://your-bucket/prefix/
JIMENG_ACCESS_KEY=AK...
JIMENG_SECRET_ACCESS_KEY=SK...
WANXIANG_API_KEY=sk-...
KELING_ACCESS_KEY=AKID...
KELING_SECRET_KEY=SECRET
LOCAL_IMAGE_PATH=example/images/Lenna.png
The examples load these automatically from .env via example/env.dart, or you can export them in your shell.
Quickstart (OpenAI Sora 2)
import 'dart:io';
import 'package:ai_video_gen_dart/ai_video_gen_dart.dart';
Future<void> main() async {
final generator = SoraGenerator(
apiKey: Platform.environment['SORA2_API_KEY'] ?? '',
);
final client = VideoGenerationClient(
options: ClientOptions(
pollIntervalMs: 5000,
downloadDir: 'example/videos', // auto-save outputs
),
);
final job = await client.generate(
generator,
UnifiedVideoRequest(
prompt: 'A slow drone shot over a neon city in the rain',
durationSeconds: SoraDurations.eightSeconds,
resolution: SoraSizes.p1080,
aspectRatio: SoraAspectRatios.landscape16x9,
),
onProgress: (status) =>
stdout.writeln('Status: ${status.status} ${status.progress ?? ''}'),
);
print(
'${job.status} ${job.progress} ${job.videoUrl} local=${job.localFilePath}',
);
}
API Overview
VideoGenerationClientis a light polling helper around anyVideoGenerator. Configure polling defaults withClientOptions(pollIntervalMsdefaults to 4000,maxPollTimeMsdefaults to 5 minutes), or call generator methods directly. SetdownloadDirto auto-save results (falls back to a system temp folder if creation is not permitted).client.generateaccepts an optionalonProgresscallback; when provided it will poll likepollUntilDone, pushing each status update via the callback and returning the finalGenerationResult.UnifiedVideoRequestfields:prompt(required) plus optionalapiKey,model,durationSeconds,aspectRatio,resolution,seed,webhookUrl,metadata(e.g., reference images),negativePrompt,guidanceScale,framesPerSecond,user. Use provider-specific DTO constants (e.g.,SoraSizes,JimengAspectRatios,WanXiangDurations) to avoid typos.pollUntilDoneacceptsPollOptionsto overridepollIntervalMsormaxPollTimeMs, and to supply a differentapiKeyfor polling if needed.GenerationResultexposesrequestId,status(queued|processing|streaming|succeeded|failed), optionalprogress(0–1),etaSeconds,videoUrl,coverUrl,errorMessage, and the originalrawResponse.VideoGenerator.promptGuideUrlis an optional official prompt guide link for the provider.VideoGenerator.capabilitiesexposes optional supported values (aspect ratios/resolutions/durations) to help pre-validate user input.
final guide = generator.promptGuideUrl;
if (guide != null) {
print('Prompt guide: $guide');
}
Providers
- Default endpoints live in each provider generator (
lib/src/providers/**); constructorbaseUrlis optional—override only when you need a custom endpoint/region. Local file paths for images are automatically converted to base64 where the provider accepts it (seelib/src/utils/payload_utils.dart). - Networking uses Dio; the default client honors
HTTPS_PROXY/HTTP_PROXY/NO_PROXYviaHttpClient.findProxyFromEnvironment. If you need custom logging/retries/proxy rules, pass a configuredDioto the generator constructor (e.g.SoraGenerator(httpClient: dio)). - OpenAI Sora 2:
https://api.openai.com/v1/videoswith bearerSORA2_API_KEY.resolutionmaps to the Sorasizefield (width x height) anddurationSecondsmaps toseconds. For image references, setmetadata['input_reference']to a local file path. UseSoraGenerator.downloadContentto fetch MP4/thumbnail/spritesheet variants. Docs: OpenAI Videos API. - Google Vertex Veo (Vertex AI): bearer
VEO_OAUTH_TOKENplusprojectId/location(constructor params); base URL defaults tohttps://{location}-aiplatform.googleapis.com. Uses long-running endpoints: start/v1/projects/{projectId}/locations/{location}/publishers/google/models/{model}:predictLongRunningand poll/v1/projects/{projectId}/locations/{location}/publishers/google/models/{model}:fetchPredictOperation. Default model isveo-3.1-generate-001(seeVeoModelIdsfor options). Veo 3.x requiresgenerateAudio;resolutionaccepts720p/1080p; durations 4/6/8s. Docs: Vertex AI Veo video generation. - ByteDance JiMeng 3.0 Pro (Volcengine): base
https://visual.volcengineapi.com, submit/?Action=CVSync2AsyncSubmitTask&Version=2022-08-31, poll/?Action=CVSync2AsyncGetResult&Version=2022-08-31, method POST with Volcengine SigV4 (Regioncn-north-1, Servicecv). SetapiKey= access key andsecretKey= secret key; per-call override can beapiKeyasAK:SK. Payload fields come fromUnifiedVideoRequest+metadata:prompt,binary_data_base64/image_urls,seed,frames,aspect_ratio,req_key(defaultjimeng_ti2v_v30_pro). Docs: Volcengine Visual (即梦 3.0 Pro) API. - Alibaba WanXiang (Image-to-Video): base
https://dashscope.aliyuncs.com, start/api/v1/services/aigc/video-generation/video-synthesis(POST withX-DashScope-Async: enable), status/api/v1/tasks/{task_id}(GET). BearerWANXIANG_API_KEY. Model viarequest.modelormetadata['model'](defaultwan2.6-i2v), requiredimg_urlinmetadata['img_url']/metadata['image'], optionalaudio_url,template, andparameters(resolution, duration, prompt_extend, shot_type, watermark, audio, seed). Docs: DashScope Video Synthesis. - Kwai Kling (可灵图生视频): base URL
https://api-beijing.klingai.com, start/v1/videos/image2video, status/v1/videos/image2video/{task_id}. Send required image viametadata['image'](URL or base64) and optional fieldsimage_tail,mode,cfg_scale,model_name,static_mask,dynamic_masks,camera_control,callback_url,external_task_id. Docs: Kling API.
Examples
example/sora_example.dart— OpenAI Sora 2 start + poll + download flow.example/jimeng3_pro_example.dart— ByteDance JiMeng 3 Pro, auto-convert local images to Base64.example/jimeng3_720p_example.dart— ByteDance JiMeng 3 720p, auto-convert local images to Base64.example/jimeng3_1080p_example.dart— ByteDance JiMeng 3 1080p, auto-convert local images to Base64.example/kling_example.dart— Kwai Kling, auto-convert local images to Base64.example/wanxiang_example.dart— Alibaba WanXiang, auto-convert local images to data:base64.example/veo_example.dart— Google Vertex Veo predictLongRunning + poll flow.
Development
- Lint/format/test:
dart format . && dart analyze && dart test - HTTP uses Dio; supply a custom
Diovia each generator constructor if you need retries, proxies, or logging.