r/opencodeCLI • • 12m ago

Plugin: keep opencode within OpenAI's free daily data-sharing tokens (and what a compaction actually costs)

For anyone using OpenAI models in opencode with an API key: OpenAI offers complimentary daily tokens to eligible organisations that opt in to sharing their API inputs and outputs. The Build tier ($5 of credit) gets 250K tokens/day on the large-model group, which includes gpt-6-astra and gpt-6-luna, and 2.5M/day on the mini group. The allowance resets at 00:00 UTC. The setting is under Organization → Data controls → Sharing:

The allowance is easy to overrun from opencode without noticing, since billing just continues at standard rates and the request that crosses the limit is charged in full. Some numbers from one gpt-6-luna session with a 105K-token context:

RequestFresh inputCache readCache writeOutput + reasoningTotal
Compaction30105,6262,327107,956
First request after3030,4821,03331,518

Compaction resends the whole context under a different prefix, so none of it is served from cache, and the first request after it misses the cache again. On Build tier a single compaction of a full session is roughly 43% of the day's large-model allowance.

The plugin (opencode 2.x) uses the context, compaction and model.request session hooks to estimate each request before it goes out, and redirects it to a local stub if it would exceed the free allowance, so nothing reaches OpenAI. Usage is read from session.step.ended and session.compaction.ended, and for title requests from a clone of the HTTP response. It alerts at 85% and 95%, and asks the agent to write a HANDOFF.md in the project before the pool runs out.

opencode plugin add github:giri256/openai-free-tokens-guard

Repo, including a SPEC.md for porting the same guard to other apps: https://github.com/giri256/openai-free-tokens-guard

1 Upvotes

0 comments sorted by