When wiring up OpenCode, Pi, or Codex, you have two ways to avoid paying per token: run open-weight models locally via Ollama, LM Studio, or vLLM, or tap into free cloud API tiers. In practice, the best workflow uses both depending on the task.
Side-by-side comparison
| Factor | Local inference (Ollama / LM Studio / vLLM) | Free cloud API tiers |
|---|---|---|
| Hardware | Needs 16–48 GB+ of VRAM or unified memory for decent speed and context | Runs on provider GPUs; works on any thin-and-light laptop |
| Privacy | Prompts never leave your machine (when tools are local too) | Prompts go to third-party servers—follow company policy and provider terms |
| Model capability | Usually limited to quantized 7B–32B models on consumer hardware | Access to frontier or full-size open-weight models |
| Tool calling | Small quantized models frequently mangle JSON tool arguments | Stronger models handle multi-step edits and tool calls reliably |
| Context window | Pushing past 64k balloons KV-cache memory and slows generation | Many endpoints offer 128k–200k context (verify the gateway’s actual cap) |
| Availability | Works offline with zero rate limits | Subject to RPM/TPM caps, outages, and credit expiration |
When local models win
Local inference is the clear winner for:
- Proprietary code or secrets: if source code, internal configs, or
.envfiles cannot leave your laptop, run a strictly local model (with cloud models and web-search features disabled in Ollama) so prompts stay off third-party servers. - High-frequency, simple chores: commit messages, unit-test stubs, format conversions, and quick error explanations run fine on a 7B–14B coding model without burning cloud rate limits.
- Offline or flaky Wi-Fi: flights, trains, and restricted networks.
Ollama exposes an OpenAI-compatible server at http://localhost:11434/v1 out of the box. Here is an OpenCode V2 config pointing at a model from ollama list:
{
"$schema": "https://opencode.ai/config.json",
"providers": {
"ollama-local": {
"package": "aisdk:@ai-sdk/openai-compatible",
"name": "Ollama Local",
"settings": {
"baseURL": "http://localhost:11434/v1",
"apiKey": "ollama"
},
"models": {
"your-local-model": { "name": "Local model" }
}
}
}
}
The "ollama" string is just a placeholder because local Ollama doesn’t require auth (remote/shared Ollama proxies may require real keys). If you use OpenCode V1, check the OpenCode V1 migration guide for provider/npm/options field names.
When free cloud APIs win
Switch to a hosted model from the free AI offers directory (for non-sensitive work) when you need:
- Multi-file refactors and tricky debugging: local 8B–14B models often lose track across ten files or emit broken tool payloads; frontier models succeed far more consistently.
- Large contexts (64k+): cloud clusters prefill long repos vastly faster than local consumer hardware.
- Quiet, cool laptops: an 8 GB or 16 GB ultrabook won’t choke on model weights.
A practical setup is two saved profiles: keep local Ollama for private code and offline edits, and use expiring free cloud credits for open-source work, algorithms, and heavy multi-file tasks.