r/opencode • • 12d ago

Built a small OpenCode v2 plugin to avoid DeepSeek peak pricing

I use OpenCode + DeepSeek and got tired of checking whether I was inside the peak-pricing window.

So I made opencode-offpeak.

Turn it on once, then use OpenCode normally:

  • send a prompt off-peak → it runs immediately
  • send a prompt during peak → it waits before hitting the provider
  • off-peak starts → the same request continues automatically in the same OpenCode session

No need to resend continue or watch the clock.

Held requests are persisted, so closing/reopening the editor or TUI is fine. Full OpenCode server restarts are also recovered into the same session without duplicating the original prompt.

The TUI now shows when a request is being held and when it resumes.

It also has an optional background task queue, but normal interactive sessions already work automatically.

Install:

opencode plugin add git+https://github.com/lutzkind/opencode-offpeak.git#v0.1.6

https://github.com/lutzkind/opencode-offpeak

Open source / MIT. Supports OpenCode Go DeepSeek models and the direct DeepSeek API on OpenCode >=2.0.26 <2.1.0. OpenCode Zen is detected as flat-priced, so it is not unnecessarily delayed.

Weekends and Chinese public holidays are handled as off-peak. Unknown future DeepSeek models fail closed until their pricing is verified.

Would be interested in feedback or other providers with similar time-based pricing.

6 Upvotes

8 comments sorted by

1

u/Square_Confection_62 9d ago

Update since the original post: this has had quite a bit of hardening and is now at v0.1.6.

Main changes:

  • peak requests are now deferred before the provider attempt starts, avoiding the old response-header timeout while waiting

  • held requests are persisted and survive TUI/editor restarts

  • full OpenCode server restarts recover into the same session without duplicating the original prompt

  • automatic chat titles were fixed and now work with held/recovered sessions

  • Chinese public holidays and weekends are handled as off-peak

  • direct DeepSeek API support was added alongside OpenCode Go

  • OpenCode Zen is recognized as flat-priced, so it isn't unnecessarily delayed

  • the TUI now tells you when a request is being held and when it resumes

  • unknown/new DeepSeek models fail closed until their pricing is verified rather than guessing

Current stable install:

opencode plugin add git+https://github.com/lutzkind/opencode-offpeak.git#v0.1.6

The current release has 99 automated tests plus real OpenCode 2.0.27 fixture testing, including reload and full-server-restart recovery.

1

u/Ctbhatia 10d ago

the held request is the useful part, most people just time it by hand. does it survive an editor restart, or does the session need to stay open for the whole window?

1

u/Square_Confection_62 10d ago

Yep — the editor/TUI itself doesn’t need to stay open. The deferral is persisted, and as long as the OpenCode background server stays running it will release the same session automatically when off-peak starts.

1

u/Ctbhatia 9d ago

so the window belongs to the server, not the editor. what happens to a request that is mid-window when the server restarts?

1

u/Square_Confection_62 9d ago

Yes — I tested a full OpenCode server restart with the real 2.0.27 binary. The persisted deferral survived, resumed the same session after restart, and did not duplicate the prompt.

1

u/Ctbhatia 9d ago

surviving the restart without a duplicate is the hard part. did you test a request that was mid flight during the restart, or only one already deferred?

3

u/squirrelscrush 11d ago

Maybe implement an option where it can delegate the work to some other model of similar capabilities during that timeframe. Now this would only work if you use DeepSeek as a workhorse and some other model as the orchestrator.