L23 · Build & preview · 6 min

Adding AI to your app, with a backup

In one sentence

When your app calls an AI model, those requests run only on your server—sending traffic first to Tokentide for lower prices and zero data retention, and switching automatically to Vercel AI Gateway whenever capacity is full so your users still get an answer without interruption.

Think of it like this

Think of a bakery that buys flour from a trusted local mill at a great price, but keeps a second supplier on standby. If the mill runs out on a busy morning, the delivery truck switches to the second supplier automatically and the bread still comes out on time.

How it works

AI calls always happen on your DefinitionbackendThe part of an app that runs on a server: it keeps data, checks logins and talks to other services.Open in the glossary → (in a Server Action, Route Handler or background job), never in the visitor's browser, so your DefinitionAPI keyA password your app uses with another service. Whoever has it can spend your money.Open in the glossary → stays secret and protected by a Definitionrate limitA cap on how often something can be done, like sign-in attempts per minute, to stop abuse.Open in the glossary →. Every text request sets max_completion_tokens—about twice the longest expected answer—so a single runaway response can never drain your balance.

Your primary provider is Tokentide (https://api.tokentide.app/v1), which is up to ~63% below list price and keeps zero copies of your prompts or answers. You set maxRetries: 0 on the Tokentide client so that if capacity is temporarily full (503), rate-limited (429), out of credit (402), or returns a server error (500/502/504) or timeout, it doesn't wait—it hands the request straight to your DefinitionfallbackA backup that answers when the main provider can't, so your app keeps working.Open in the glossary →, Vercel AI Gateway (https://ai-gateway.vercel.sh/v1), and honors Retry-After before trying the primary again.

Not every error should trigger the backup. If your key is wrong (401 invalid_api_key) or restricted (403 ip_not_allowed or account_restricted), your app falls back so users aren't stuck AND alerts you to fix the key. But if the request itself is broken—like 403 model_not_allowed or any other 4xx—your app does not fall back; your agent fixes the request and checks the DefinitionmodelThe AI system that produces answers, like the one behind your coding agent.Open in the glossary → pair in both catalogs.

To keep user data private and outputs safe, your DefinitionlogYour app's diary: one line per event. When something breaks, the logs say what happened.Open in the glossary → records the cost (X-Tokentide-Charge-USD), request ID (X-Request-Id), feature name and answering provider—never the DefinitionpromptThe message you give an AI model. Clear prompts get better results.Open in the glossary → or the model's answer. And because model output is untrusted, your code validates and escapes it before showing or saving it.

1 · Your serverGuarded requestChecks session and rate limit, sets max_completion_tokens, keeps keys on the server.
2 · TokentidePrimary AI (maxRetries: 0)Answers first at lower cost and zero data retention; refused requests aren't charged.
3 · Vercel AI GatewayAutomatic fallbackTakes over immediately on 503, 429, 402, 5xx or timeout so the user still gets an answer.
FIG. 1 · Every AI request tries Tokentide first with zero retries and switches to Vercel AI Gateway if capacity isn't available.

Tokentide first. Vercel AI Gateway when it can't answer.

Main providerTokentide
  • Up to ~63% below list price The price falls through the UTC day (about 25% to 47% below list), and the Low Tide lane is about 30% cheaper still for work that can wait.
  • Keeps no copy of your data Zero data retention: Tokentide never stores prompts or outputs, and each key has a privacy mode.
  • Spending you control Prepaid credit from 10 USD that doesn't expire, spend caps per key and per account, and refused requests are never charged.
  • No new code to learn OpenAI-compatible: the same SDKs, with a different base URL and key.
Backup providerVercel AI Gateway
  • Answers when Tokentide can't Daily supply sold out (503), rate limits (429), no credit or a spend cap (402), server errors and timeouts all move to the Gateway at once.
  • Many models behind one key Add credit or bring your own provider keys, inside the Vercel dashboard you already use.
  • Pay only when it's used Pay as you go: on a normal day it handles little or nothing.
Together
  • The lowest price whenever Tokentide has capacity, and an answer every time.
  • No retries on Tokentide (maxRetries: 0), so a refusal reaches the backup in milliseconds; Retry-After is honoured.
  • Calls stay on the server, with a token limit on every request and the fallback tested in dev before launch.

Figures from Tokentide's documentation, checked 8 Nov 2026. Prices change daily; always check the live price. Lesson: adding AI to your app, with a backup · How we choose tools and our commercial relationships

What it looks like in your project

Your agent uses the tokentide-api and ai-sdk skills to wire both providers with matching model IDs, and you paste TOKENTIDE_API_KEY and AI_GATEWAY_API_KEY into .env.local and Vercel (using low-cap keys for local work). Before merging, your agent tests the fallback in a DefinitionPreviewA private test link Vercel makes for each change, so you can try it before it goes live.Open in the glossary → by pointing the Tokentide client at a dead address and confirming the Gateway answers cleanly.

Copy for your agent

Set up our AI helper on the server using the tokentide-api and ai-sdk skills: Tokentide first with maxRetries: 0, Vercel AI Gateway as fallback, max_completion_tokens set, and logging only cost and provider—never prompts or outputs.

Quick check · 1 question

Why do we set `maxRetries: 0` on the primary Tokentide client?

Go deeper

Next lessonAfter launch: error alerts and monitoring

Last reviewed Nov 8, 2026