DEV Community

Daniel Dong
Daniel Dong

Posted on

5 things I wish I knew before building my first AI-powered app.

5 things I wish I knew before building my first AI-powered app.

1. Switch models early, not when you're forced to

I hardcoded one provider. Three months later they changed pricing.
Rewriting every API call took a weekend. If I'd used an abstraction
layer from day one, the migration would have been one string change.

# Don't do this:
openai.OpenAI(api_key="sk-xxx", base_url="https://api.deepseek.com/v1")

# Do this:
openai.OpenAI(api_key="mb-xxx", base_url="https://aibridge-api.com/v1")
# Same code. Change model="deepseek-chat" to model="qwen-max" anytime.
Enter fullscreen mode Exit fullscreen mode
  1. Most of your requests don't need the expensive model I ran everything through the strongest model for two months. Then I checked: 87% of my prompts were "summarize this" or "classify this" or "rewrite this." Tasks the cheap model handles identically.

Route simple stuff to the 0.27/Mmodel.Savethe7/M model for the
10% of prompts that actually need it. Your AWS bill isn't one tier — neither should your AI bill be.

  1. Caching is free latency improvement Same system prompt, same user prompt, same temperature? Return the cached response. One header: X-Cache-TTL: 3600. 200ms instead of 1200ms. Zero tokens. Zero cost.

I didn't build a Redis layer. The API gateway handles it.

  1. Rate limits will hit you at 2 AM Every provider has them. DeepSeek's RPM limits. Moonshot's TPM caps. They all hit during peak traffic — which, for a global app, is always.

The fix isn't "buy a higher tier." It's "have a fallback model."
When deepseek-chat returns 429, your next request goes to qwen-max.
The user never notices. Your code doesn't change — just the model
string in the config.

  1. Nobody will sign up if you make them Email → password → verification code → API key. Four steps. Bounce rate: 68%.

I added two things: a free playground that needs no signup (10 requests/day,
all models), and GitHub OAuth (one click, 5 seconds, no email).

The playground especially — people type a prompt, see it work, then register.
Conversion went from 1.4% to 19%.

The stack I landed on
After all five lessons, this is the setup:

import openai
client = openai.OpenAI(
    api_key="mb-xxx",
    base_url="https://aibridge-api.com/v1"
)

# Route by task type
model = "deepseek-chat" if task == "simple" else "glm-4-plus"
client.chat.completions.create(model=model, messages=messages)
Enter fullscreen mode Exit fullscreen mode

One key. 15 Chinese AI models. Streaming, function calling, JSON mode.
Free tier: 500K tokens/month. Try it without signing up at the playground.

aibridge-api.com/playground.html
aibridge-api.com

1

2

3

4

5

6

Top comments (0)