DEV Community

Cover image for Stop Paying Too Much for AI: Use Multiple LLM Providers Like a Pro
vaasav kumar
vaasav kumar

Posted on

Stop Paying Too Much for AI: Use Multiple LLM Providers Like a Pro

If you're getting started with AI, one of the biggest challenges is cost and flexibility.

Most tutorials lock you into a single provider. But in real-world projects, you should be able to:

Switch models easily πŸ”„
Compare outputs βš–οΈ
Use free providers when possible πŸ’Έ

In this blog, I’ll show a simple way to use multiple AI providers in one setup.

πŸ’‘ Learn AI Without Spending Money

One of the biggest blockers for developers getting into AI is cost.

Not everyone can afford paid APIs β€” and that’s completely fine.

That’s why tools like:

🧠 Cerebras (free-tier models)
πŸ”“ Open/free LLM providers
πŸ§ͺ Community-hosted APIs

are game changers.

pip install openai
Enter fullscreen mode Exit fullscreen mode

Generate API Keys

OpenAI β†’ https://platform.openai.com/
Cerebras β†’ https://cloud.cerebras.ai/
ArliAI β†’ https://www.arliai.com/account

Beginners can use Jupyter Notebook to try the following code while others can follow in their own code editors.

πŸ”‘ Set API Keys

import os

os.environ['ARLIAI_API_KEY'] = "xxx"
os.environ['CEREBRAS_API_KEY'] = "yyy"
os.environ['OPENAI_API_KEY'] = "zzz"
Enter fullscreen mode Exit fullscreen mode

βš™οΈ Configure Multiple LLM Providers

# Set LLM providers to change models easily
llm_providers = {
    "arliai": {
        "api_key": os.getenv("ARLIAI_API_KEY"),
        "base_url": "https://api.arliai.com/v1",
        "model": "Llama-3.3-70B-ArliAI-RPMax-v3",
    },
    "cerebras": {
        "api_key": os.getenv("CEREBRAS_API_KEY"),
        "base_url": "https://api.cerebras.ai/v1",
        "model": "llama3.1-8b",
    },
    "openai": {
        "api_key": os.getenv("OPENAI_API_KEY"),
        "base_url": "https://api.openai.com/v1",
        "model": "gpt-4o-mini",
    }
}
Enter fullscreen mode Exit fullscreen mode

🧠 Helper Function to Switch Providers

from openai import OpenAI

def set_llm(provider_name):
    provider = llm_providers[provider_name]
    client = OpenAI(
        api_key=provider["api_key"],
        base_url=provider["base_url"]
    )
    return client
Enter fullscreen mode Exit fullscreen mode

πŸ§ͺ Test with Cerebras (Free Model)

llm = set_llm('cerebras')

name = llm.invoke("I want to open a restaurant for Indian food. Suggest a fancy name for this.")
print(name.content)
Enter fullscreen mode Exit fullscreen mode

βœ… Sample Output (Cerebras)

Here are some fancy name suggestions for an Indian restaurant:

1. **Maharaja's Mosaic**: This name evokes the grandeur and richness of Indian royalty, while also hinting at the diverse flavors and cuisines that Indian food has to offer.
2. **Tandoori Nights**: This name captures the essence of Indian food, with the tandoor oven being a staple of Indian cuisine. It also has a romantic and exotic connotation.
3. **Kashmiri Kitchen**: This name suggests a high-end, sophisticated dining experience, with a focus on the rich culinary traditions of the Kashmir region.
4. **Dhaba Royale**: A dhaba is a type of Indian restaurant, but by adding "Royale" to the name, you're implying a luxurious and upscale dining experience.
5. **Saffron & Spice**: Saffron is a highly prized spice in Indian cuisine, and by combining it with "Spice", you're highlighting the complex and aromatic flavors that Indian food is known for.
6. **Mumbai Magic**: This name captures the energy and vibrancy of India's largest city, while also hinting at the magic and wonder of Indian cuisine.
7. **Garam Gourmet**: "Garam" means "hot" in Hindi, and "Gourmet" implies a high-end dining experience. This name suggests a restaurant that serves spicy, flavorful food in a sophisticated setting.
8. **Rajasthani Rhapsody**: This name suggests a restaurant that serves the rich and regal cuisine of Rajasthan, with a focus on the region's unique flavors and traditions.
9. **Spice Route Bazaar**: This name captures the essence of Indian cuisine, with its complex blend of spices and flavors. The word "Bazaar" also implies a lively and vibrant atmosphere.
10. **Ayurvedic Eats**: This name suggests a restaurant that serves food that is not only delicious but also healthy and nourishing, with a focus on the principles of Ayurvedic medicine.

I hope these suggestions help inspire you to find the perfect name for your Indian restaurant!
Enter fullscreen mode Exit fullscreen mode

πŸ” Test the Same with OpenAI

llm = set_llm('openai')

name = llm.invoke("I want to open a restaurant for Indian food. Suggest a fancy name for this.")
print(name.content)
Enter fullscreen mode Exit fullscreen mode

βœ… Sample Output (OpenAI)

Here are some fancy name suggestions for your Indian restaurant:

1. **Saffron & Spice**
2. **Curry Couture**
3. **The Royal Masala**
4. **Tandoori Treasures**
5. **Noble Naan**
6. **Mystic Flavors**
7. **Bollywood Bites**
8. **Spice Symphony**
9. **Heritage Haveli**
10. **Kashmiri Delight**

Feel free to mix and match or modify any of these names to better suit your vision!
Enter fullscreen mode Exit fullscreen mode

πŸš€ Why This Approach Matters

This is not just a simple example β€” it’s a real-world pattern.

With this setup, you can:

πŸ”„ Switch between providers instantly
πŸ’Έ Use free models like Cerebras
⚑ Compare outputs across models
πŸ§ͺ Experiment without vendor lock-in

πŸ§‘β€πŸ’» For Developers

Don’t just read about AI β€” build with it.

Start small:

  • Try different prompts
  • Compare model outputs

With the right setup, any developer can build AI-powered applications using both free and paid models.

So:

  • Try multiple providers
  • Experiment freely
  • Build something useful

In our next blog, we’ll build helper functions using LangChain to make this setup even more powerful.

Top comments (0)