DEV Community

Dubhe
Dubhe

Posted on

How to Build a Multi-Model AI App in 10 Minutes (With Code)

Have you ever wanted to use different AI models for different tasks — fast for simple queries, reasoning for complex problems, vision for images — without managing multiple API keys?

Here's how to build a multi-model app in 10 minutes.

The Concept

Instead of picking one model, you route each request to the model that fits best:

Simple chat → Fast model ($0.30/M)
Code review → Code model ($0.80/M)
Image analysis → Vision model ($5.00/M)
Complex logic → Reasoning model ($6.00/M)
Enter fullscreen mode Exit fullscreen mode

Step 1: Install the SDK

npm install openai
Enter fullscreen mode Exit fullscreen mode

Step 2: Set Up the Client

import OpenAI from 'openai';

const dubhe = new OpenAI({
  baseURL: 'https://dubhehub.com/v1',
  apiKey: process.env.DUBHE_API_KEY
});
Enter fullscreen mode Exit fullscreen mode

Step 3: Route Requests by Type

async function routeRequest(task, content) {
  const modelMap = {
    'chat': 'dubhe-fast',
    'code': 'dubhe-code',
    'reason': 'dubhe-reasoning',
    'vision': 'dubhe-vision'
  };

  return await dubhe.chat.completions.create({
    model: modelMap[task] || 'dubhe-fast',
    messages: [{ role: 'user', content }]
  });
}
Enter fullscreen mode Exit fullscreen mode

Step 4: Use It

// Simple chat — costs ~$0.00022
const chat = await routeRequest('chat', 'Explain what Docker is');

// Code review — costs ~$0.0028  
const review = await routeRequest('code', 'Review this function for bugs: ...');

// Deep reasoning — costs ~$0.009
const analysis = await routeRequest('reason', 'Analyze this business case...');
Enter fullscreen mode Exit fullscreen mode

Why This Matters

Switching between models lets you optimize for cost and quality at the same time. One API key, one SDK, multiple price points.

The free tier (100K tokens) is enough to build and test your entire prototype.

👉 Try it at dubhehub.com

Top comments (0)