๐—•๐˜‚๐—ถ๐—น๐—ฑ๐—ถ๐—ป๐—ด ๐—” ๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ฒ๐—ฟ๐—น๐—ฒ๐˜€๐˜€ ๐—ฃ๐—ฟ๐—ผ๐˜…๐˜† ๐—ณ๐—ผ๐—ฟ ๐—”๐—œ ๐—”๐—ฃ๐—œ๐˜€

I wanted to add a chatbot to my side project last month.

The goal was simple. Take user messages. Send them to an AI API. Stream the response back. Keep the API key safe.

I tried calling the API directly from the browser. This failed for two reasons.

I tried building an Express server next. It worked, but I did not want to manage a VPS. I did not want to worry about uptime or restarts for a small project.

I chose a serverless function instead. I used Vercel Edge Functions.

Why this works:

The setup is simple. The function receives the message, calls the AI, and streams the result back to your frontend.

However, serverless is not perfect. I found four main issues:

  1. Cold starts. There is a small delay when the function starts.
  2. Timeouts. Most providers limit how long a function can run.
  3. Rate limiting. Users can spam your endpoint and increase your bill. Use Redis or Upstash to stop this.
  4. Error handling. You need to format errors so your users understand them.

My advice for the future:

This approach is great for MVPs and small projects. Do not use it if you need sub-100ms response times or if you have millions of requests every day.

For most developers, a serverless proxy is enough to get started safely.

How do you handle AI API calls in your production apps?

Source: https://dev.to/__c1b9e06dc90a7e0a676b/building-a-serverless-proxy-for-ai-apis-lessons-learned-34lj