r/opencode • • 5d ago

Another OpenCode model router, but this one tries not to burn your prompt cache

Yes, another model router 😅

I built an OpenCode V2 plugin inspired by Pi’s smart-router. It uses a small judge model to route each turn to a model from a pool you choose. The judge can run locally—Qwen 4B on oMLX or llama.cpp, for example—or through an OpenAI-compatible endpoint.

The obvious problem is that switching to a cheaper model can cost more if you lose a warm prompt cache. So the router estimates cached input cost for the current model against cold input cost for alternatives. It keeps a pin unless there’s a good reason to switch, like the task needing more capability or an adequate alternative being much cheaper. There’s also a guard against bouncing between models.

You can choose cost, quality, or balanced preferences, mix local and cloud models, and choose how aggressively to favor the cache. If the judge times out, deterministic rules take over. /router explain shows the last decision and /router timing shows the overhead.

I’m not going to claim it saves everyone money. It depends on your models, cache pricing, workload, and whether the router makes good calls. I’d like to find out where it gets those calls wrong.

If you try it, I’d appreciate issues or feedback—especially bad model picks, unexpected cache behavior, judge latency, or setup problems.

GitHub: https://github.com/231self/opencode-router

opencode plugin add @231self/opencode-router
2 Upvotes

2 comments sorted by

1

u/scott91429 4d ago

Does the estimate account for cache warming on the destination model over later turns? A cold switch may look costly per turn but pay off across a longer run.

1

u/Broad_Abies9390 4d ago

Not exactly but as a derivation of jitter reducing routing policy that essentially prevents the router from switching on each turn. Afaik in like 2-3 turns the cache is around 80% full but the session might anyways drift away from it so it might stay relatively cold therfore I think ANT have costs for cache reads vs. cache write (not sure)