DEV Community

Cover image for 🤖 Run AI Coding Models for FREE with OpenCode + OpenRouter
Nitin Kumar
Nitin Kumar

Posted on AI-assisted

🤖 Run AI Coding Models for FREE with OpenCode + OpenRouter

Hey guys, while everyone else keeps paying for ChatGPT's monthly subscription, we'll be getting AI to write code for us right here—for free. 😎 Today's plan is to set up OpenCode on our system and run it using OpenRouter's free models. Just have a little patience and keep your tea ready. ☕

📚 Today's Menu

  1. 🧐 OpenCode: What & Why
  2. 💻 Install OpenCode
  3. 🔑 Configure OpenCode with OpenRouter
  4. 🔌 Connect it on your local system
  5. 🚀 Run the app and pray
  6. 🎬 Wrapping up

🧐 1. OpenCode: What & Why

📖 Introduction

OpenCode is an open-source AI coding agent that lives in your terminal. A chatbot answers your question and leaves the copy-pasting to you. An agent actually opens your project, reads the files, edits them, and runs commands. Pehle aap code copy-paste karte the, ab AI khud mehnat karta hai, aur aap credit lete ho. 🤝

🎯 Why use OpenCode?

  • 🔓 Open-source: You can read the code, tweak it, and nobody locks you in. Transparency ka full dose.
  • 🧠 Model freedom: OpenAI, Anthropic, Google, OpenRouter, local models, whatever you like. Sab ke saath dosti. 🤗
  • 🌐 OpenRouter support: One account, one API key, and a whole buffet of models.
  • 🚫 No vendor lock-in: If one provider gets expensive or moody, switch models and carry on. Workflow wahi rahega.
  • 🕵️ Agentic coding: It reads, edits, debugs, and works across your whole codebase, not just one pasted snippet.
  • ⌨️ Terminal-first: Developers who love the command line will feel at home. Mouse? Kaun sa mouse? 🐭
  • 🧩 Extensible: It supports MCP, plugins, custom commands, and agents.
  • 🏠 Local-model support: You can run models on your own machine if your laptop can take the heat. 🔥
  • 💸 Cost control: Use cheap or free models for easy jobs and save the fancy ones for serious work.
  • 🎛️ Customizable: Agents, models, permissions, and per-project behaviour are all configurable.

💻 2. Install OpenCode

Since you're on Windows, there are two routes. One is easy, and the other is what the developers recommend. 😏

🅰️ Option 1: Windows + npm

  1. 📦 Install Node.js first if you don't have it. Without it, the next step will just throw an error at you.
  2. 🔵 Open PowerShell.
  3. Run:
   npm install -g opencode-ai
Enter fullscreen mode Exit fullscreen mode
  1. ✅ Check that it installed:
   opencode --version
Enter fullscreen mode Exit fullscreen mode
  1. 🎬 Start it:
   opencode
Enter fullscreen mode Exit fullscreen mode

If you see a version number, you're good. If you see a red error, check that Node.js is installed and that you opened a fresh PowerShell window afterwards. 🔄

🅱️ Option 2: Windows + WSL ⭐

The OpenCode team recommends WSL (Windows Subsystem for Linux) for the smoothest experience on Windows. Basically, they are saying Linux is the happy place, and honestly, same. 🐧

Inside WSL, run:

curl -fsSL https://opencode.ai/install | bash
Enter fullscreen mode Exit fullscreen mode

Then verify and start it the same way:

opencode --version
opencode
Enter fullscreen mode Exit fullscreen mode

💡 Which one should you pick? If you just want to get going, use npm. If you spend most of your day in a terminal anyway, WSL is the better long-term home.


🔑 3. Configure OpenCode with OpenRouter

🌐 What is OpenRouter, anyway?

Think of OpenRouter as the Swiggy of AI models. 🛵 You don't visit every restaurant (provider) separately. You order from one app with one account, and it delivers from many kitchens. Some of those dishes are even free.

🆕 Create an OpenRouter account

  1. Go to the OpenRouter sign-up page and register.

✨ Bonus point: People use tempmail.app for sign-up, but most temp mail services get rejected. A normal email is safer, and you won't lose your account later. 😅

  1. 🏠 Open your Dashboard and go to Keys.
  2. ➕ Click Create API Key.
  3. 🏷️ Name it something sensible, like OpenCode.
  4. 📋 Copy the key immediately. OpenRouter shows it only once, so if you lose it, you create a new one. Bhool gaye toh bhugto. 😬

⚠️ Warning: Never share this API key publicly, and above all never push it to GitHub. Bots scan public repos all day, and they will find your key faster than your relatives find your salary. 💰


🔌 4. Configure OpenCode on your local system

Once this step is done, you can run free-tier models straight from your machine. 🎉

  1. 🔗 Inside OpenCode, type /connect. A provider selection screen will appear.
  2. 🎯 Select OpenRouter from the list.
  3. 🔐 When it asks for an API key, paste the one you generated earlier. Check that no extra spaces sneaked in. 👀
  4. 🧠 Type /models and pick the models you want to use.

💡 You can browse every free model on OpenRouter through this link. Window shopping is free. 🛍️

📌 Note: Add at least one model first, such as nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free or openrouter/free. After that, you can ask OpenCode to add more models for you.

🎁 Lucky dip: openrouter/free automatically picks an available free model based on what your request needs. Decision lene ka jhanjhat khatam. 🙌

🧱 Your final setup

┌─────────────────┐
│       You       │
└────────┬────────┘
         ↓
┌─────────────────┐
│    OpenCode     │
│  Coding Agent   │
└────────┬────────┘
         ↓
┌─────────────────┐
│   OpenRouter    │
│   API Gateway   │
└────────┬────────┘
         ↓
┌─────────────────────────┐
│     Free AI Models      │
│ Nemotron / Gemma / etc. │
└─────────────────────────┘
Enter fullscreen mode Exit fullscreen mode

🚨 Warning: OpenRouter lists 25+ free models, but "free" comes with limits, including a stated 50 requests per day. So don't treat it like an all-you-can-eat thali. 🍛 Use your requests wisely.


🚀 5. Run the OpenCode application

🛠️ Optional: make the openrouter shortcut

If typing openrouter gives a "not recognized" error, create the shortcut yourself. Open your PowerShell profile:

notepad $PROFILE
Enter fullscreen mode Exit fullscreen mode

Add this line, save, and restart PowerShell:

function openrouter { opencode }
Enter fullscreen mode Exit fullscreen mode

🧪 The test

  1. Open PowerShell and type openrouter.
  2. Give it the easiest prompt in the world:
   Create a simple Python Hello World program
Enter fullscreen mode Exit fullscreen mode
  1. Wait. The model is thinking, so don't smash Enter like it's a lift button. 🛗
  2. If it asks permission to create a file, say yes. It's not a scam. 🙏

✅ It works?

Mubarak ho! 🎊 Now add more models and compare them. Some are fast and shallow, others are slow and thoughtful, just like your friends. 😄

❌ It doesn't work?

Don't panic. 😤 Troubleshoot like a pro:

  • 🔍 openrouter not recognized → shortcut or PATH missing, or PowerShell not restarted
  • 🔑 Authentication error → wrong or expired API key, so paste it again
  • 🐢 Model not responding → free models get overloaded, so try another one
  • 📉 Requests failing suddenly → you may have hit the daily free limit, so come back tomorrow

🎬 Wrapping up

You now have an AI coding agent in your terminal, powered by free models, with no subscription needed. 🥳 Is it as sharp as the premium models? No. Does it cost ₹0? Haan. Toh bas, kaam chalao. 😎


Hope you liked what you saw above, do like if you've gained some knowledge. Do comment out if you're facing any issues in any step, would love to help troubleshoot.

Top comments (0)