DEV Community

TokenHub
TokenHub

Posted on

# I Broke My AI API Business 3 Times in 24 Hours — Here's What I Learned

Two weeks ago I launched TokenHub, an AI API relay platform. Last night, I broke the entire system three separate times trying to add more models. Here's what happened, and what I learned.

The Setup

TokenHub runs on a $12/month VPS with multiple upstream providers covering 500+ models — GPT, Claude, DeepSeek, Qwen, GLM, Mistral, Llama, and more. The gateway is One API, a Go-based model router that handles authentication, quota management, and channel routing. It's been solid... until it wasn't.

Crash #1: The Group Column

One API has an internal model registry stored in its SQLite database. Each model belongs to a channel, and each entry has a group column that must be set to "default". If it's NULL or empty, the model simply doesn't show up — you get "No available channel" errors with zero explanation.

I had 517 models with empty group fields. The fix is one SQL statement:

UPDATE abilities SET "group"='default' WHERE "group" IS NULL;
Enter fullscreen mode Exit fullscreen mode

But running this through a shell script kept failing because "group" is a reserved SQL keyword. Every attempt corrupted the database. I burned 3 hours on this.

Lesson: Use Python scripts uploaded via SFTP to modify the database. Shell escaping is a trap.

Crash #2: The Duplicate Abilities

After fixing the group column, I got a UNIQUE constraint violation. The model list has entries like deepseek/deepseek-chat and I was also adding short names like deepseek-chat. Some of these short names already existed from other channels, creating duplicates.

The fix was deduplication before the group update:

DELETE FROM abilities WHERE rowid NOT IN (
    SELECT MIN(rowid) FROM abilities GROUP BY model, channel_id
);
Enter fullscreen mode Exit fullscreen mode

Another hour lost.

Crash #3: The $ Sign Eater

While fixing the payment page to show CNY for WeChat/Alipay, I kept losing the dollar sign. The HTML template has ${{ product['price'] }} but every time I modified the app.py file through a shell command, the $ got eaten by the shell's variable expansion.

Lesson: Never pipe Python code through bash. Write to a file via SFTP, then execute with python3.

What I Actually Shipped

After 6 hours of debugging:

  • 500+ models live across multiple upstream providers
  • GPT-5.5 and Claude Opus 4.8 available
  • All model ratios synced with real-time upstream pricing
  • Auto-balance monitoring for all channels
  • API subdomain to bypass bot detection for desktop clients

The Numbers (Week 3)

  • 500+ active models
  • $12/month server cost
  • Revenue covering costs (barely)
  • Zero downtime complaints (I was the only one testing at 1 AM)

Should You Build an AI API Relay?

If you're doing it for money — probably not. The market is crowded and margins are razor-thin.

If you're doing it to learn — absolutely. I now understand API gateways, rate limiting, model pricing economics, and SQLite internals better than any tutorial could teach.

What's Next

I'm looking for the first 10 paying customers. If you need AI models without the usual barriers (Chinese phone number, foreign credit card, VPN), check it out. Starter plan is $0.10 for 1M tokens.


Built by one person on $12/month servers. Follow the journey on Twitter/X @TokenHub.

Top comments (1)

Collapse
 
tokenhub profile image
TokenHub

😪