DEV Community

Cover image for Cut AI API Costs by Up to 80% with a Safe Provider Fallback
you.bot
you.bot

Posted on

Cut AI API Costs by Up to 80% with a Safe Provider Fallback

Lower AI API prices are useful only when the routing design preserves predictable behavior.

The practical pattern is:

  1. use the lower-cost route as primary;
  2. keep the existing provider integration as fallback;
  3. fall back only after a confirmed terminal outcome; and
  4. reconcile unknown task states instead of duplicating them.

With you.bot, failed or resultless media tasks are refunded. For model configurations where its listed price is below the standard comparison price, a successful primary call costs less, while a refunded failure followed by fallback has the same model execution cost as calling the standard provider directly.

Price snapshot: up to 80% less

The largest differences are easiest to understand side by side. This selection includes both the highest-saving configurations and widely used text, image, and video models:

Model and configuration Standard comparison you.bot listed price Max savings with bonus
Grok Imagine Video 1.5, image-to-video, 480p (per second) $0.0800 $0.0178 80%
GPT Image 2, text-to-image, 1K (per generation) $0.2190 $0.0564 77%
GPT-5.6 Luna, input (per 1M tokens) $1.0000 $0.5097 54%
Claude Sonnet 5, input (per 1M tokens) $3.0000 $1.5367 53%
Gemini 3.6 Flash, input (per 1M tokens) $1.5000 $0.7871 52%
Gemini Omni, 4s 4K video without video input (per generation) $1.8667 $1.0565 49%

Max savings with bonus includes the qualifying 10% bonus on the $1,250 top-up. It is calculated as 1 - ((you.bot listed price / 1.10) / standard comparison price) and rounded to the nearest whole percent. Without that bonus, the corresponding base-price differences are 77.8%, 74.2%, 49.0%, 48.8%, 47.5%, and 43.4%.

Prices are a point-in-time snapshot and vary by exact model, operation, resolution, duration, and billing unit. Check the current you.bot price table before making a routing decision.

The cost model

Let:

Y = you.bot price
S = standard provider price
p = primary-route success rate
Enter fullscreen mode Exit fullscreen mode

Then:

route_first_cost = pY + (1 - p)S
direct_only_cost = S
savings = p(S - Y)
Enter fullscreen mode Exit fullscreen mode

If Y < S, the route-first architecture reduces blended spend whenever some requests succeed through the primary route.

For example, the current GPT Image 2 snapshot lists 1K text-to-image generation at $0.0564 through you.bot and $0.219 as the standard comparison price, a 74.2% difference for that configuration.

Do not generalize one row to the entire catalog. Compare the same model, operation, resolution, duration, and billing unit.

Why a normal timeout is not a fallback signal

Assume an application creates an asynchronous video task and waits 60 seconds. The client times out, but the task continues running. If the application immediately creates the same video with another provider, it can receive and pay for two outputs.

The correct response to an unknown state is reconciliation:

type FinalResult =
  | { state: "completed"; outputUrl: string; route: "you.bot" | "fallback" }
  | { state: "failed"; reason: string };

type PrimaryState =
  | { state: "completed"; outputUrl: string }
  | { state: "terminal_failure"; reason: string }
  | { state: "running"; taskId: string }
  | { state: "unknown"; taskId?: string };

async function generateWithSafeFallback(input: GenerationInput): Promise<FinalResult> {
  const primary = await createWithYouBot(input);

  if (primary.state === "completed") {
    return { ...primary, route: "you.bot" };
  }

  const reconciled =
    primary.state === "running" || primary.state === "unknown"
      ? await reconcileYouBotTask(primary.taskId)
      : primary;

  if (reconciled.state === "completed") {
    return { ...reconciled, route: "you.bot" };
  }

  if (reconciled.state !== "terminal_failure") {
    throw new Error("Primary execution state is unknown; fallback is not safe yet.");
  }

  const fallback = await createWithExistingProvider(input);
  return { ...fallback, route: "fallback" };
}
Enter fullscreen mode Exit fullscreen mode

The adapter functions above are intentionally separated. Each one should normalize provider-specific responses into a small internal state machine.

Persist state before polling

Store at least:

interface RoutedGeneration {
  localRequestId: string;
  primaryTaskId?: string;
  modelId: string;
  primaryState: "creating" | "running" | "completed" | "terminal_failure" | "unknown";
  fallbackState: "not_started" | "running" | "completed" | "failed";
  fallbackReason?: string;
  primaryPriceUsd?: number;
  fallbackPriceUsd?: number;
  createdAt: string;
  updatedAt: string;
}
Enter fullscreen mode Exit fullscreen mode

Persist the primary task ID before the worker begins polling. That lets a replacement worker reconcile the original task instead of creating a new one after a crash.

Separate user latency from execution state

A product can stop making the user wait without declaring the generation failed.

For example:

  • after 45 seconds, return a pending response to the frontend;
  • continue reconciliation in a background worker;
  • notify the user through a webhook, WebSocket, or status page;
  • use a longer execution deadline before considering manual intervention.

This keeps user experience responsive without producing duplicate billable work.

Use documented failure classes

Create an allowlist of outcomes that can trigger fallback. Examples might include:

  • task reached a documented terminal failed state;
  • completed response contains no usable result and is refund-eligible;
  • create request was definitively rejected before acceptance; or
  • an operator has reconciled an otherwise unknown task.

Do not use a broad catch block that sends every exception to the fallback provider.

Authentication errors, invalid inputs, insufficient balance, and policy failures may also fail through the fallback route. Retrying those problems can add latency without improving completion.

Measure blended cost

The metric that matters is not the advertised price in isolation:

blended cost per successful output =
  (primary charges + fallback charges) / successful outputs
Enter fullscreen mode Exit fullscreen mode

Track it by exact model configuration together with:

  • primary completion rate;
  • fallback rate;
  • unknown-state rate;
  • end-to-end latency;
  • refunded-task reconciliation; and
  • duplicate-output rate.

The goal is both economic and operational: capture the lower primary price while preserving an independent route for continuity.

The current you.bot price table is available at https://you.bot/pricing, and its task lifecycle is documented at https://you.bot/docs.

Top comments (0)