DEV Community

YingSuan AI
YingSuan AI

Posted on

Build a Multi-Model AI Chatbot in 15 Minutes: One API Key for DeepSeek, GLM and Qwen

Most chatbot tutorials lock you into a single model. Real products rarely work that way: you want a fast, cheap model for casual conversation, a reasoner for math and logic, and a large model for long-form generation. The usual catch is juggling three provider accounts, three SDKs, and three billing systems.

There is a simpler way. In this tutorial we build one chatbot that switches between DeepSeek, GLM and Qwen at runtime — all behind a single OpenAI-compatible endpoint from Yingsuan AI. Total time: about 15 minutes.

What you need

  • A free API key — 100 trial calls and 3 permanently free models, no credit card required (get it here)
  • Python 3.9+ or Node.js 18+
  • The openai SDK (yes, we reuse the OpenAI SDK — the gateway is fully compatible)

Step 1: One client, many models

Because Yingsuan AI speaks the same /v1/chat/completions protocol as OpenAI, the entire multi-model setup is just a dictionary of model names:

from openai import OpenAI

MODELS = {
    "fast":     "glm-4-flash",        # permanently free, great for small talk
    "smart":    "deepseek-chat",      # strong all-round model
    "thinker":  "deepseek-reasoner",  # step-by-step reasoning
    "writer":   "qwen2.5-72b",        # long-form generation
    "coder":    "deepseek-v3",        # coding tasks
}

client = OpenAI(
    base_url="https://yingsuan.top/v1",
    api_key="YOUR_YINGSUAN_API_KEY"
)
Enter fullscreen mode Exit fullscreen mode

Switching models is now a one-line change — no new SDK, no new account, no new retry logic.

Step 2: The chatbot class (Python)

Here is a minimal but complete multi-model chatbot with conversation memory:

class MultiModelChatbot:
    def __init__(self, api_key: str):
        self.client = OpenAI(
            base_url="https://yingsuan.top/v1",
            api_key=api_key
        )
        self.model_key = "fast"
        self.history = []

    def switch(self, model_key: str):
        if model_key not in MODELS:
            raise ValueError(f"Unknown model: {model_key}")
        self.model_key = model_key

    def chat(self, user_msg: str) -> str:
        self.history.append({"role": "user", "content": user_msg})
        response = self.client.chat.completions.create(
            model=MODELS[self.model_key],
            messages=self.history
        )
        reply = response.choices[0].message.content
        self.history.append({"role": "assistant", "content": reply})
        return reply


bot = MultiModelChatbot(api_key="YOUR_YINGSUAN_API_KEY")

# Casual chat on the free fast model
print(bot.chat("Hi! Introduce yourself in one sentence."))

# Switch to a reasoner for a hard question
bot.switch("thinker")
print(bot.chat("A train covers 120 km in 90 minutes. Average speed in m/s?"))
Enter fullscreen mode Exit fullscreen mode

The conversation history is a plain OpenAI-format message list, so it works identically across every model in the registry — even after switching mid-conversation.

Step 3: Same thing in JavaScript

Node.js developers get the identical pattern:

import OpenAI from "openai";
import readline from "node:readline/promises";

const MODELS = {
  fast: "glm-4-flash",
  smart: "deepseek-chat",
  thinker: "deepseek-reasoner"
};

const client = new OpenAI({
  baseURL: "https://yingsuan.top/v1",
  apiKey: process.env.YINGSUAN_API_KEY
});

const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
const history = [];
let active = "fast";

console.log('Chat ready. Type "/model smart" to switch, "exit" to quit.');

while (true) {
  const input = await rl.question("you> ");
  if (input === "exit") break;

  if (input.startsWith("/model ")) {
    const key = input.split(" ")[1];
    if (MODELS[key]) { active = key; console.log(`switched to ${MODELS[key]}`); }
    continue;
  }

  history.push({ role: "user", content: input });
  const res = await client.chat.completions.create({
    model: MODELS[active],
    messages: history
  });
  const reply = res.choices[0].message.content;
  history.push({ role: "assistant", content: reply });
  console.log("bot>", reply);
}
rl.close();
Enter fullscreen mode Exit fullscreen mode

Run it, then try /model thinker before a tricky question and /model fast again afterwards. You just built model routing into a CLI chatbot in ~40 lines.

Why this architecture pays off

  • One secret to manage. One API key, one environment variable, one rotation policy.
  • Zero-cost experimentation. Swap model names the moment a better model ships — no SDK migration, no rewrites.
  • Discoverability. GET /v1/models with your key lists every model available on your tier, so your app can offer a model picker dynamically.

What it costs to try

Nothing to start: every new key includes 100 free trial calls, and free models like glm-4-flash and qwen2.5-7b stay free permanently. Paid tiers are available when you outgrow the free quota.

Get your key and build it

Grab your free API key at yingsuan.top/api.html — no credit card, two-line setup from any OpenAI SDK project. Full endpoint docs are on the same page.


Which model routing rule would you add to this chatbot? Cost caps, language detection, task classification? Tell me in the comments.

Top comments (0)