If you’re hitting OpenAI’s quota limits on a free account, you can easily switch to other AI providers that offer generous free tiers. The AI SDK makes this transition seamless with its unified interface.
Free Tier Limits: While these providers offer free credits, they still
have usage limits. Monitor your usage to avoid unexpected charges.
Let’s modify your chat route to use an alternative provider. Here are examples for each:
Copy
import { groq } from "@ai-sdk/groq";import { convertToModelMessages, streamText, UIMessage } from "ai";export const maxDuration = 30;export async function POST(req: Request) { const { messages }: { messages: UIMessage[] } = await req.json(); const result = streamText({ model: groq("llama-3.3-70b-versatile"), system: `You are a helpful assistant. Check your knowledge base before answering any questions. Only respond to questions using information from tool calls. If no relevant information is found in the tool calls, respond, "Sorry, I don't know."`, messages: convertToModelMessages(messages), }); return result.toUIMessageStreamResponse();}
Different providers offer different models. Here’s a quick comparison:
Provider
Model
Context Window
Speed
Best For
Groq
llama-3.3-70b-versatile
8K
Ultra-fast
General chat
DeepInfra
Llama-3.3-70B-Instruct
8K
Fast
Code & reasoning
Together.ai
Llama-3.3-70B-Instruct
8K
Medium
Open source focus
Fireworks
llama-v3-70b-instruct
8K
Fast
Production apps
Recommendation: Start with Groq for its speed and generous free tier. The
Llama 3.3 70B model is excellent for general conversation and reasoning tasks.
You can implement a fallback strategy to switch providers if one fails:
app/api/chat/route.ts
Copy
import { groq } from "@ai-sdk/groq";import { deepinfra } from "@ai-sdk/deepinfra";import { convertToModelMessages, streamText, UIMessage } from "ai";export const maxDuration = 30;export async function POST(req: Request) { const { messages }: { messages: UIMessage[] } = await req.json(); try { // Try Groq first const result = streamText({ model: groq("llama-3.3-70b-versatile"), system: `You are a helpful assistant. Check your knowledge base before answering any questions. Only respond to questions using information from tool calls. If no relevant information is found in the tool calls, respond, "Sorry, I don't know."`, messages: convertToModelMessages(messages), }); return result.toUIMessageStreamResponse(); } catch (error) { // Fallback to DeepInfra const result = streamText({ model: deepinfra("meta-llama/Llama-3.3-70B-Instruct"), system: `You are a helpful assistant. Check your knowledge base before answering any questions. Only respond to questions using information from tool calls. If no relevant information is found in the tool calls, respond, "Sorry, I don't know."`, messages: convertToModelMessages(messages), }); return result.toUIMessageStreamResponse(); }}