← Back to articles
Detailed Usage

Connecting Free Models to OpenCode in Practice

⚠️ Pending Update · 2026-08-29 Verification · Content may be outdated, please refer to official docs Updated: 2026-08-29 · Status: Pending Verification

Introduction

OpenCode itself is free — your only cost is the model API. The good news is that OpenRouter, Groq, and Together AI all expose free-tier models over an OpenAI-compatible protocol. This article gives you three ready-to-use configurations and compares their real-world behavior on coding tasks.

架构图

flowchart LR A[OpenCode CLI] --> B[OpenRouter] A --> C[Groq] A --> D[Together AI] B --> B1[Llama:free] C --> C1[Llama 3.3 70B] D --> D1[Qwen 2.5 72B] B1 --> E[Zero-cost terminal coding] C1 --> E D1 --> E

Prerequisites

Make sure OpenCode is installed (see us-01) and grab these keys:

Manage all of them via environment variables — never hardcode them into config files.

Config File

Write the following to opencode.json in your project root:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "openrouter": {
      "options": { "baseURL": "https://openrouter.ai/api/v1" },
      "models": {
        "meta-llama/llama-3.3-70b-instruct:free": { "name": "Llama 3.3 70B (free)" }
      }
    },
    "groq": {
      "options": { "baseURL": "https://api.groq.com/openai/v1" },
      "models": {
        "llama-3.3-70b-versatile": { "name": "Llama 3.3 70B Groq" },
        "llama-3.1-8b-instant": { "name": "Llama 3.1 8B Instant" }
      }
    },
    "together": {
      "options": { "baseURL": "https://api.together.xyz/v1" },
      "models": {
        "meta-llama/Llama-3.3-70B-Instruct-Turbo": { "name": "Llama 3.3 70B Together" }
      }
    }
  },
  "model": "groq/llama-3.3-70b-versatile"
}

Inject Keys

export OPENROUTER_API_KEY="sk-or-v1-..."
export GROQ_API_KEY="gsk_..."
export TOGETHER_API_KEY="..."

OpenCode matches each provider to an environment variable of the same name, so you never hardcode keys in the config.

Launch and Switch

opencode

Inside the TUI, press Ctrl+M to switch between configured models. Use Groq's llama-3.3-70b-versatile for fast everyday coding (first-token latency often under 300ms), fall back to OpenRouter's :free Llama for heavier reasoning, and pick llama-3.1-8b-instant for the cheapest code completion.

Free-tier Comparison

Provider Strength Weakness Best for
Groq Blazing fast 128K context, strict TPM Real-time chat, completion
OpenRouter :free Many models Heavy queuing Complex reasoning
Together Stable Few fully free models Mid-complexity tasks

Model Selection Tips

In practice, free models differ noticeably by task: for code completion use Groq's llama-3.1-8b-instant (low latency, large free quota); for complex refactors or algorithms pick OpenRouter's llama-3.3-70b-instruct:free (70B params, stronger reasoning); for Chinese prose use Qwen on Together. Configure all of them and switch on demand.

Troubleshooting

  • 429 Too Many Requests: Free tiers have RPM caps. Wait 30 seconds or switch providers — configuring all three lets you Ctrl+M to the next on failure.
  • Garbled non-English output: Set export LANG=en_US.UTF-8, or append Always respond in Simplified Chinese to the prompt.
  • OpenRouter :free returns 403: Verify your account has a credit card on file — OpenRouter requires verification even for free models and will not charge you.
  • context length exceeded on 8B models: Switch to a 70B model or split the file into chunks.

You now have a fully free terminal AI coding environment.

Pitfalls and Best Practices

  • Multi-provider switching needs /model command: OpenCode does not auto-fallback; when one provider hits 429 you must manually switch to the backup.
  • Keep token context small: most free models have 8K-32K context; chunk long files before sending.
  • Never commit API keys: use the apiKey: "${ENV_VAR}" reference syntax; pre-commit hooks alone are not enough.
  • Prefer Groq over OpenRouter for speed: Groq is consistently faster for daily coding; reserve OpenRouter :free as the degraded fallback.

🚀 Get Started: One-Click Free API Access

Want to call all the free models above with a single API key, no need to sign up for each provider? Apishare.cc provides a unified API Key — one key, 100+ models, free models at zero cost.

👉 Register on Apishare.cc → Get your unified API Key

📊 Want to see more free model rankings? Check out the Sep 2026 Free LLM API Rankings →


Get Started: APIShare Free API Directory


About the Free API Aggregator

The models covered in this guide are all served through the APIShare free API aggregator, which gives you one key for the whole catalog.

More in this category

Free AI Content Moderation API Guide 2026: Llama Guard 3 vs Perspective vs OpenAIFree OCR and Document Parsing API in PracticeIntegrating Free APIs into Your Local IDEApplying for an OpenRouter API Key and Understanding PricingUsing the Hugging Face Inference Client

Ready to use free LLM APIs?

APIShare aggregates free AI APIs worldwide — sign up and get bonus credits.