varg-ai

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Environment Detection

环境检测

Before generating anything, determine the rendering mode.
Run
bash scripts/setup.sh
from the skill directory to auto-detect, or check manually:
bunffmpegMode
NoNoCloud Render -- read cloud-render.md
YesNoCloud Render -- read cloud-render.md
YesYesLocal Render (recommended) -- read local-render.md
VARG_API_KEY
is required for all modes. Get one at https://varg.ai
在生成任何内容之前,请先确定渲染模式。
从技能目录运行
bash scripts/setup.sh
进行自动检测,或手动检查:
bunffmpeg渲染模式
云端渲染 -- 查看cloud-render.md
云端渲染 -- 查看cloud-render.md
本地渲染(推荐)-- 查看local-render.md
所有模式都需要
VARG_API_KEY
。可前往https://varg.ai获取。

Critical Rules

核心规则

Everything you know about varg is likely outdated. Always verify against this skill and its references before writing code.
  1. Never guess model IDs -- consult models.md for current models, pricing, and constraints.
  2. Function calls for media, JSX for composition --
    Image({...})
    creates media,
    <Clip>
    composes timeline. Never write
    <Image prompt="..." />
    .
  3. Cache is sacred -- identical prompt + params = instant $0 cache hit. When iterating, keep unchanged prompts EXACTLY the same. Never clear cache.
  4. One image per Video --
    Video({ prompt: { images: [img] } })
    takes exactly one image. Multiple images cause errors.
  5. Duration constraints differ by model -- kling-v3: 3-15s (integer only). kling-v2.5: ONLY 5 or 10. Check models.md.
  6. Gateway namespace -- use
    providerOptions: { varg: {...} }
    , never
    fal
    , when going through the gateway (both modes).
  7. Renders cost money -- 1 credit = 1 cent. A typical 3-clip video costs $2-5. Use preview mode (local) or cheap models to iterate.
你所了解的varg相关信息很可能已过时。在编写代码前,请务必对照本技能及其参考文档进行验证。
  1. 切勿猜测模型ID -- 请查阅models.md获取当前可用模型、定价及限制条件。
  2. 媒体生成用函数调用,合成用JSX --
    Image({...})
    用于生成媒体,
    <Clip>
    用于时间轴合成。切勿编写
    <Image prompt="..." />
  3. 缓存至关重要 -- 相同的提示词+参数=即时免费命中缓存。迭代时,请完全保留未修改的提示词。切勿清除缓存。
  4. 每个视频仅含一张图片 --
    Video({ prompt: { images: [img] } })
    仅接受一张图片。多张图片会导致错误。
  5. 不同模型的时长限制不同 -- kling-v3:3-15秒(仅支持整数)。kling-v2.5:仅支持5秒或10秒。请查阅models.md
  6. 网关命名空间 -- 当通过网关调用时(两种模式均适用),请使用
    providerOptions: { varg: {...} }
    ,切勿使用
    fal
  7. 渲染会产生费用 -- 1积分=1美分。一个典型的3片段视频花费约2-5美元。迭代时请使用预览模式(本地)或低成本模型。

Quick Start

快速开始

Cloud Render (no bun/ffmpeg needed)

云端渲染(无需bun/ffmpeg)

bash
undefined
bash
undefined

Submit TSX code to the render service

提交TSX代码至渲染服务

curl -s -X POST https://render.varg.ai/api/render
-H "Authorization: Bearer $VARG_API_KEY"
-H "Content-Type: application/json"
-d '{"code": "const img = Image({ model: fal.imageModel("nano-banana-pro"), prompt: "a cabin in mountains at sunset", aspectRatio: "16:9" });\nexport default (<Render width={1920} height={1080}><Clip duration={3}>{img}</Clip></Render>);"}'
curl -s -X POST https://render.varg.ai/api/render
-H "Authorization: Bearer $VARG_API_KEY"
-H "Content-Type: application/json"
-d '{"code": "const img = Image({ model: fal.imageModel("nano-banana-pro"), prompt: "a cabin in mountains at sunset", aspectRatio: "16:9" });\nexport default (<Render width={1920} height={1080}><Clip duration={3}>{img}</Clip></Render>);"}'

Poll for result (repeat until "completed" or "failed")

轮询获取结果(重复调用直到状态为"completed"或"failed")

curl -s https://render.varg.ai/api/render/jobs/JOB_ID
-H "Authorization: Bearer $VARG_API_KEY"

Full details: [cloud-render.md](references/cloud-render.md)
curl -s https://render.varg.ai/api/render/jobs/JOB_ID
-H "Authorization: Bearer $VARG_API_KEY"

详细说明:[cloud-render.md](references/cloud-render.md)

Local Render (bun + ffmpeg)

本地渲染(需bun + ffmpeg)

tsx
/** @jsxImportSource vargai */
import { Render, Clip, Image } from "vargai/react"
import { createVarg } from "@vargai/gateway"

const varg = createVarg({ apiKey: process.env.VARG_API_KEY! })

const img = Image({
  model: varg.imageModel("nano-banana-pro"),
  prompt: "a cabin in mountains at sunset",
  aspectRatio: "16:9"
})

export default (
  <Render width={1920} height={1080}>
    <Clip duration={3}>{img}</Clip>
  </Render>
)
bash
bunx vargai render video.tsx --preview   # free preview
bunx vargai render video.tsx --verbose   # full render (costs credits)
Full details: local-render.md
tsx
/** @jsxImportSource vargai */
import { Render, Clip, Image } from "vargai/react"
import { createVarg } from "@vargai/gateway"

const varg = createVarg({ apiKey: process.env.VARG_API_KEY! })

const img = Image({
  model: varg.imageModel("nano-banana-pro"),
  prompt: "a cabin in mountains at sunset",
  aspectRatio: "16:9"
})

export default (
  <Render width={1920} height={1080}>
    <Clip duration={3}>{img}</Clip>
  </Render>
)
bash
bunx vargai render video.tsx --preview   # 免费预览
bunx vargai render video.tsx --verbose   # 完整渲染(消耗积分)
详细说明:local-render.md

Single Asset (no video composition)

单一资产生成(无需视频合成)

For one-off images, videos, speech, or music without building a multi-clip template:
bash
curl -X POST https://api.varg.ai/v1/image \
  -H "Authorization: Bearer $VARG_API_KEY" \
  -d '{"model": "nano-banana-pro", "prompt": "a sunset over mountains"}'
Full API reference: gateway-api.md
如需一次性生成图片、视频、语音或音乐,无需构建多片段模板:
bash
curl -X POST https://api.varg.ai/v1/image \
  -H "Authorization: Bearer $VARG_API_KEY" \
  -d '{"model": "nano-banana-pro", "prompt": "a sunset over mountains"}'
完整API参考:gateway-api.md

How to Write Video Code

如何编写视频代码

Video code has two layers: media generation (function calls) and composition (JSX).
tsx
// 1. GENERATE media via function calls
const img = Image({ model: ..., prompt: "..." })
const vid = Video({ model: ..., prompt: { text: "...", images: [img] }, duration: 5 })
const voice = Speech({ model: ..., voice: "rachel", children: "Hello!" })

// 2. COMPOSE via JSX tree
export default (
  <Render width={1080} height={1920}>
    <Music model={...} prompt="upbeat electronic" duration={10} volume={0.3} />
    <Clip duration={5}>
      {vid}
      <Title position="bottom">Welcome</Title>
    </Clip>
    <Captions src={voice} style="tiktok" />
  </Render>
)
视频代码分为两层:媒体生成(函数调用)和合成(JSX)。
tsx
// 1. 通过函数调用生成媒体
const img = Image({ model: ..., prompt: "..." })
const vid = Video({ model: ..., prompt: { text: "...", images: [img] }, duration: 5 })
const voice = Speech({ model: ..., voice: "rachel", children: "Hello!" })

// 2. 通过JSX树进行合成
export default (
  <Render width={1080} height={1920}>
    <Music model={...} prompt="upbeat electronic" duration={10} volume={0.3} />
    <Clip duration={5}>
      {vid}
      <Title position="bottom">Welcome</Title>
    </Clip>
    <Captions src={voice} style="tiktok" />
  </Render>
)

Component Summary

组件汇总

ComponentTypePurpose
Image()
Function callGenerate still image
Video()
Function callGenerate video (text-to-video or image-to-video)
Speech()
Function callText-to-speech audio
<Render>
JSXRoot container -- sets width, height, fps
<Clip>
JSXTimeline segment -- duration, transitions
<Music>
JSXBackground audio (always set
duration
!)
<Captions>
JSXSubtitle track from Speech
<Title>
JSXText overlay
<Overlay>
JSXPositioned layer
<Split>
/
<Grid>
JSXLayout helpers
Full props: components.md
组件类型用途
Image()
函数调用生成静态图像
Video()
函数调用生成视频(文本转视频或图像转视频)
Speech()
函数调用文本转语音音频
<Render>
JSX根容器 -- 设置宽度、高度、帧率
<Clip>
JSX时间轴片段 -- 时长、转场效果
<Music>
JSX背景音频(务必设置
duration
!)
<Captions>
JSX基于Speech生成的字幕轨道
<Title>
JSX文本叠加层
<Overlay>
JSX定位图层
<Split>
/
<Grid>
JSX布局辅助组件
完整属性说明:components.md

Provider Differences (Cloud vs Local)

渲染模式差异(云端 vs 本地)

Cloud RenderLocal Render
No imports needed
import { ... } from "vargai/react"
fal.imageModel("nano-banana-pro")
varg.imageModel("nano-banana-pro")
fal.videoModel("kling-v3")
varg.videoModel("kling-v3")
elevenlabs.speechModel("eleven_v3")
varg.speechModel("eleven_v3")
Globals are auto-injectedMust call
createVarg()
云端渲染本地渲染
无需导入
import { ... } from "vargai/react"
fal.imageModel("nano-banana-pro")
varg.imageModel("nano-banana-pro")
fal.videoModel("kling-v3")
varg.videoModel("kling-v3")
elevenlabs.speechModel("eleven_v3")
varg.speechModel("eleven_v3")
全局变量自动注入必须调用
createVarg()

Cost & Iteration

成本与迭代

  • 1 credit = 1 cent. nano-banana-pro = 5 credits, kling-v3 = 150 credits, speech = 20-25 credits.
  • Cache saves money. Keep unchanged prompts character-for-character identical across iterations.
  • Preview first (local mode only):
    --preview
    generates free placeholders to validate structure.
  • Full pricing: models.md
  • 1积分=1美分。nano-banana-pro=5积分,kling-v3=150积分,语音生成=20-25积分。
  • 缓存节省成本。迭代时,请完全保留未修改的提示词。
  • 先预览(仅本地模式支持):
    --preview
    生成免费占位符以验证结构。

References

参考文档

Load these on demand based on what you need:
NeedReferenceWhen to load
Render via APIcloud-render.mdNo bun/ffmpeg, or user wants cloud rendering
Render locallylocal-render.mdbun + ffmpeg available
Patterns & workflowsrecipes.mdTalking head, character consistency, slideshow, lipsync
Model selectionmodels.mdChoosing models, checking prices, duration constraints
Component propscomponents.mdNeed detailed props for any component
Better promptsprompting.mdUser wants cinematic / high-quality results
REST APIgateway-api.mdSingle-asset generation or Render API details
Debuggingcommon-errors.mdSomething failed or produced unexpected results
Full examplestemplates.mdNeed complete copy-paste-ready templates
根据需求按需加载以下文档:
需求参考文档加载时机
通过API渲染cloud-render.md无bun/ffmpeg,或用户需要云端渲染
本地渲染local-render.md已安装bun + ffmpeg
模式与工作流recipes.md制作虚拟主播、角色一致性、幻灯片、唇形同步
模型选择models.md选择模型、查看定价、时长限制
组件属性components.md需要任何组件的详细属性说明
提示词优化prompting.md用户需要电影级/高质量结果
REST APIgateway-api.md单一资产生成或渲染API细节
调试common-errors.md出现失败或意外结果
完整示例templates.md需要可直接复制使用的完整模板