<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: leojxu</title>
    <description>The latest articles on DEV Community by leojxu (@leojxu).</description>
    <link>https://dev.to/leojxu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4046018%2F1768ffce-462e-49de-8fdd-38aa1c578857.png</url>
      <title>DEV Community: leojxu</title>
      <link>https://dev.to/leojxu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/leojxu"/>
    <language>en</language>
    <item>
      <title>Routing Between Video Models Without Leaking the Abstraction</title>
      <dc:creator>leojxu</dc:creator>
      <pubDate>Fri, 24 Jul 2026 19:02:37 +0000</pubDate>
      <link>https://dev.to/leojxu/routing-between-video-models-without-leaking-the-abstraction-55h4</link>
      <guid>https://dev.to/leojxu/routing-between-video-models-without-leaking-the-abstraction-55h4</guid>
      <description>&lt;p&gt;If you build on a single video generation model, you will rewrite your integration when it gets deprecated. If you build on several, you spend your time writing adapters. Here is what I learned choosing the second option.&lt;/p&gt;

&lt;h2&gt;
  
  
  The parameters do not line up
&lt;/h2&gt;

&lt;p&gt;Every provider has a different idea of the same concept:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Duration&lt;/strong&gt;: some take seconds, some take frame counts, some only accept a fixed enum&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Aspect ratio&lt;/strong&gt;: &lt;code&gt;"16:9"&lt;/code&gt; vs &lt;code&gt;{width, height}&lt;/code&gt; vs a named preset&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Seeds&lt;/strong&gt;: supported, ignored, or silently non-deterministic&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Image conditioning&lt;/strong&gt;: URL, base64, or a pre-uploaded asset ID&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A lowest-common-denominator interface is tempting and wrong — you lose the capabilities you are paying for. The alternative that held up: a &lt;strong&gt;common core plus a typed passthrough&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;VideoRequest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
  &lt;span class="na"&gt;durationSec&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;        &lt;span class="c1"&gt;// normalised, adapter converts&lt;/span&gt;
  &lt;span class="na"&gt;aspect&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;16:9&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;9:16&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1:1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;ImageInput&lt;/span&gt;
  &lt;span class="nx"&gt;providerOptions&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nb"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;unknown&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;  &lt;span class="c1"&gt;// escape hatch, typed per adapter&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The core covers what every provider supports. The escape hatch means using a provider-specific feature does not require redesigning the interface.&lt;/p&gt;

&lt;h2&gt;
  
  
  Async is the actual hard part
&lt;/h2&gt;

&lt;p&gt;Video generation takes minutes, so every provider is asynchronous — and each has invented its own async:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Polling with a job ID&lt;/li&gt;
&lt;li&gt;Webhook callbacks&lt;/li&gt;
&lt;li&gt;Server-sent events&lt;/li&gt;
&lt;li&gt;A queue position field that sometimes goes &lt;em&gt;backwards&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Normalising this matters more than normalising parameters. What worked: adapters expose a single &lt;code&gt;poll(jobId): Promise&amp;lt;JobState&amp;gt;&lt;/code&gt; and internally hide whatever the provider does. &lt;code&gt;JobState&lt;/code&gt; is a small discriminated union — &lt;code&gt;queued | running | done | failed&lt;/code&gt; — with a normalised &lt;code&gt;progress&lt;/code&gt; when available and &lt;code&gt;undefined&lt;/code&gt; when not.&lt;/p&gt;

&lt;p&gt;Do not fabricate progress. A spinner that lies is worse than a spinner that says "still working."&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure modes deserve normalising too
&lt;/h2&gt;

&lt;p&gt;Providers fail differently: content policy rejections, transient 5xx, quota exhaustion, silent truncation. Mapping these into a common taxonomy is what makes retry logic possible:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;retryable&lt;/code&gt; — backoff and retry&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;policy&lt;/code&gt; — do not retry, surface to user&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;quota&lt;/code&gt; — do not retry, switch provider or fail loudly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Getting this wrong means retrying a policy rejection 5 times and burning credits on a request that will never succeed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Credits across providers
&lt;/h2&gt;

&lt;p&gt;If you expose one balance over several backends with different pricing, you need a normalisation table and you need to be honest that it is an approximation. I run this in production at &lt;a href="https://hyper-frames.com" rel="noopener noreferrer"&gt;HyperFrames&lt;/a&gt; — text or image in, routed across Kling, Veo, Wan and others, one balance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveat
&lt;/h2&gt;

&lt;p&gt;This abstraction is worth it above roughly three providers. Below that, adapters cost more than they save — just write the integrations directly and move on.&lt;/p&gt;

</description>
      <category>api</category>
      <category>architecture</category>
      <category>ai</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
