Does an OpenCode Timeout Charge You? Check Usage Before Retrying

Match the model calls from a timed-out OpenCode session to settled usage. Find the last completed step, check the request ID and partial work, then decide what to retry.

Does an OpenCode Timeout Charge You? Check Usage Before Retrying

An OpenCode session can time out after several model calls have settled. Reconcile the run one request at a time. On Modelflare, a request that fails before output or gets a model error is refunded if funds were reserved. A client cancellation or connection drop after streaming starts can be charged for the tokens already generated. The settled usage record tells you what actually happened to a particular request. Modelflare usage and cost

Identify which timeout you saw

What you observed Evidence to save What to check next
The local runner stopped OpenCode Version, deadline, exit status and last event Find completed steps and the last step still open when the process stopped.
The server returned an HTTP error HTTP status, error code and the response request ID Read the response and usage for that ID.
Text arrived and the stream broke Last received event, whether a terminal error arrived and the request ID if available Check whether the request settled for partial usage or ended with a provider failure.

Save a UTC start and stop time, the exact model name and the test key's label. Check the workspace before restarting. A run can leave a patch or untracked file even when the session ends without a final message. If it could also have changed an external system, confirm that action's outcome with the system that owns it. Modelflare guide to timeouts by request phase

Capture a short, read-only OpenCode run

Start in a disposable workspace with a short README.md that lists two release checks and a unique marker. Use a configured OpenCode provider and a test key. Substitute its provider/model selector and note the OpenCode version in the record. The example uses GNU timeout to bound the local process.

opencode --version
timeout 30s opencode run --format json --model '<provider>/<model>' \
  'Read README.md and report the two release checks and the marker. Do not write files.' \
  > run.events.jsonl 2> run.stderr
printf 'run exit status: %s\n' "$?"

Record a normal completion as a baseline if the command finishes within the deadline. For a timeout case, choose a shorter local deadline in another run and keep both records. GNU timeout uses exit status 124 for a timed-out command. Compare that status with the deadline and event timestamps. Keep raw event files on your machine because they can include task text. OpenCode command reference · OpenCode setup on Modelflare · GNU timeout manual

For OpenCode JSON logs that expose step_start and step_finish, the following filter keeps the step markers and timings. Record the event format alongside your client version.

jq -c 'select(.type == "step_start" or .type == "step_finish") |
  {event: .type, at: .timestamp, reason: .part.reason}' run.events.jsonl

Match the calls to Modelflare usage

Filter Usage Logs to your test key and time window. If your client or trace provides the X-ModelFlare-Request-Id response header, search by that value. For a missing ID, use the same key, exact model, a narrow time window and matching usage counts. Accept the match only when those fields identify one record.

Keep one row for each gateway request Record
Client observation Session step, timestamp and whether the stream finished or failed
Gateway identifiers Request ID, key label, model and effective group
Usage and settlement Input and output tokens, cache counts when available, recorded charge and any matched refund
Result Matched, pending or ambiguous

Calculate the run's confirmed cost from its matched settled charges and applicable refunds, with each posted entry counted once. If the recorded charge is already net of a refund, use it as shown. Keep unresolved requests separate. A wallet balance observed during pre-deduction can change again when usage settles. A gateway route fallback can still be one request billed at the group that served it, while a fresh client retry creates another request to account for. Modelflare usage and cost · Track every API attempt

Decide what to retry

  1. Inspect the workspace and run the task's acceptance check. Keep any result that already passes.
  2. Reconcile an uncertain write with the destination that owns it before repeating that action. Let unresolved usage remain pending in your cost report.
  3. Retry a bounded unfinished step with the same acceptance check. Record its own request ID and settlement so you can account for both attempts.

The procedure uses documented client flags and Modelflare billing rules. The reproduced error, request count and charges depend on the exact client, model, route and deadline used in your run. Modelflare fallback and retry matrix