For Indie Developers, the Most Expensive Thing Isn't Servers—It's Time: Building a Vue3 Chat Component with a Unified Gateway
For indie developers building products, the most expensive thing isn't servers—it's time. Take an AI chat feature, for example. The traditional route: pick a model, compare prices, register accounts with each provider, read each provider's docs, handle SDK differences, write an adapter layer. If things go smoothly, that's two weeks; if not, debugging and rework alone will eat up half your schedule.
I recently helped a small team build a Vue3 chat component, with the backend unified through ThisToken.AI's gateway. In practice, from registration to having the component running in a page took half a day; with streaming output, error handling, and model switching added, the full version went live in three days. This article lays out the complete path, focusing on two things: how to get your first piece of working code as fast as possible, and which pitfalls you can avoid in advance when building the wrapper.
Why Unify the Gateway First, Then Talk About Wrapping
A common approach for small teams is to call a provider's official API directly from the frontend. The problems come later: switching models requires code changes, using multiple models means maintaining multiple sets of call logic, and exposing the Key in the frontend is a security risk. The value of a unified gateway is that all models go through the same endpoint with the same protocol (OpenAI-compatible format)—you only need to change a model name parameter.
On cost (check the official pricing page for actual prices), unified billing means you don't have to top up and experiment separately across multiple platforms, which makes budgeting far more manageable. On time, integrating a new model goes from "rewrite the call logic" to "change a string"—that's the biggest saving.
Step 1: Register and Get Your API Key
- Open https://api.thistoken.ai/register and register with your email;
- Go to the console and create a new Key on the API Key management page;
- Copy and save it—the Key is only shown in full once, at creation time.
Tip: for local development, store the Key in a .env file; don't hardcode it into your component repository.
Step 2: Get Your First Piece of Code Running
Don't rush to write the component yet. Use the following JavaScript in a Node environment to verify your Key and gateway connectivity—you'll have results in two minutes:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.THISTOKEN_API_KEY,
baseURL: "https://api.thistoken.ai/v1",
});
async function main() {
const stream = await client.chat.completions.create({
model: "gpt-4o-mini", // 模型名以网关控制台支持的列表为准
messages: [{ role: "user", content: "用一句话介绍你自己" }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
}
main();Note the line baseURL: "https://api.thistoken.ai/v1"—the gateway is OpenAI-protocol compatible, so the official SDK can be reused directly. That's the key to "running on day one." If you're using Python, the equivalent is OpenAI(base_url="https://api.thistoken.ai/v1"), with all other parameters identical, so teams with both language stacks can share the same integration documentation.
Step 3: Build the Vue3 Component
Once verification passes, move the call logic into a useChat composable, with the component handling only rendering. Here's the skeleton:
// composables/useChat.js
import { ref } from "vue";
export function useChat(model = "gpt-4o-mini") {
const messages = ref([]);
const loading = ref(false);
async function send(content) {
messages.value.push({ role: "user", content });
loading.value = true;
try {
const res = await fetch("/api/chat", { // 走自己的后端代理,避免 Key 出现在前端
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
base_url: "https://api.thistoken.ai/v1",
model,
messages: messages.value,
stream: true,
}),
});
const reader = res.body.getReader();
const decoder = new TextDecoder();
let reply = "";
messages.value.push({ role: "assistant", content: "" });
while (true) {
const { done, value } = await reader.read();
if (done) break;
reply += decoder.decode(value);
messages.value[messages.value.length - 1].content = reply;
}
} finally {
loading.value = false;
}
}
return { messages, loading, send };
}Three key points for the wrapper:
Keep the Key on the backend. The frontend component calls your own /api/chat, and the backend attaches the Key when forwarding to the gateway. This is the security baseline, and it's also the only place where you can later add rate limiting and usage tracking.
Make the model name a parameter. Because the gateway unifies the protocol, switching models is just changing the model string. You can build a dropdown that lets users pick a tier, with different tiers corresponding to different response speeds and costs, without changing any call code.
Don't skip streaming output. Without streaming, a chat component's user experience drops significantly. The ReadableStream reading approach above can be moved into the component as-is.
The Time Ledger: Before and After
| Step | Direct Multi-Provider | Unified Gateway |
|---|---|---|
| Registration & Key management | Once per provider, multiple top-ups | One registration, unified billing |
| Integration & debugging | Read each provider's docs | One protocol working means all work |
| Switching models | Change call logic, ~1-2 days | Change one string, minutes |
| Prototype to launch | ~2 weeks | 3 days or less |
For this team, the ten-plus working days saved went straight into product polish—that's where an indie developer's effort should go.
Final Recommendations
Before launch, remember three small things: add basic concurrency limits to your backend proxy; set up usage alerts in the console; and put the model list in a config file instead of scattering it throughout the code. With all that done, your chat component becomes a long-term reusable asset you can carry directly into your next project.
If you haven't registered yet, you can spend two minutes doing it now: https://api.thistoken.ai/register . Run the verification code above, and you'll see your first AI reply today.
---
Ready to try it yourself? Sign up at https://api.thistoken.ai/register to get your API key and start building.
Ready to try Token.AI?
Create a project-level API Key, enable channels in the console, and configure routing, budgets, and audit logs.
注册 ThisToken.AI 并获取 API Key