TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Use the Gemini API with OpenAI Fallback in TypeScript

72 pointsby l5870uoo9yabout 1 month ago

8 comments

bearjawsabout 1 month ago
The Vercel AI SDK abstracts against all LLMs, including locally running ones. It even handles file attachments well, which is something people are using more and more.<p><a href="https:&#x2F;&#x2F;sdk.vercel.ai&#x2F;docs&#x2F;introduction" rel="nofollow">https:&#x2F;&#x2F;sdk.vercel.ai&#x2F;docs&#x2F;introduction</a><p>It uses zod for types and validation, I&#x27;ve loved using it to make my apps swap between models easily.
评论 #43609751 未加载
评论 #43607127 未加载
评论 #43605729 未加载
评论 #43613984 未加载
评论 #43605406 未加载
评论 #43607083 未加载
评论 #43607945 未加载
thesandlordabout 1 month ago
I&#x27;ve been using using [BAML](<a href="https:&#x2F;&#x2F;github.com&#x2F;boundaryml&#x2F;baml">https:&#x2F;&#x2F;github.com&#x2F;boundaryml&#x2F;baml</a>) to do this, and it works really well. Lets you have multiple different fallback and retry policies, and returns strongly typed outputs from LLMs.
calebkaiserabout 1 month ago
I would recommend looking at OpenRouter, if anyone is interested in implementing fallbacks across model providers. I&#x27;ve been using it in several projects, and the ability to swap across models without changing any implementation code&#x2F;without managing multiple API keys has been incredibly nice:<p><a href="https:&#x2F;&#x2F;openrouter.ai&#x2F;docs&#x2F;quickstart" rel="nofollow">https:&#x2F;&#x2F;openrouter.ai&#x2F;docs&#x2F;quickstart</a>
评论 #43606712 未加载
visargaabout 1 month ago
I just had very bad JSON mode operation with gemini-1.5-flash and 2.0-flash models using their own library &#x27;google-generativeai&#x27;. Either can&#x27;t follow JSON formatting correctly, or renders string fields with no end until max_tokens. Pretty bad for Gemini, when open models like Qwen do a better job of a basic information extraction to JSON task.
评论 #43610934 未加载
评论 #43610240 未加载
DeborahEmeni_about 1 month ago
I’ve done something similar using OpenRouter and fallback chains across providers. It’s super helpful when you’re hitting rate limits or need different models for different payload sizes. I would love to see more people share latency data, though, especially when chaining Gemini + OpenAI like this.
nextworddevabout 1 month ago
Just use Litellm
_pdp_about 1 month ago
Prompt won’t just work from one mother transplanted into another.
评论 #43610460 未加载
ilrwbwrkhvabout 1 month ago
Typescript looks so ugly visually. It gives me PHP vibes. I think it&#x27;s the large words at the first column of the eye line:<p>export const<p>function<p>type<p>return<p>etc<p>This makes scanning through the code really hard because your eye has to jump horizontally.
评论 #43606902 未加载
评论 #43605598 未加载
评论 #43606124 未加载
评论 #43606191 未加载