Back to Blog

OpenCode Calls the API While Idle? Check Session Warming

Developer Workflow Analysis8176
OpenCode Calls the API While Idle? Check Session Warming

You stop typing, leave the coding session open, and later see more model requests in your usage records. Before assuming that a key has leaked or that the gateway counted incorrectly, identify the process and purpose behind those requests.

One feature worth checking is OpenCode session warming. The current OpenCode warming documentation describes periodic model requests intended to preserve short-lived provider state, such as prompt caches. The feature is disabled by default. When enabled, warming requests are real requests that may consume tokens, incur charges, and count against rate limits.

That does not mean every unexplained request is warming. Other clients, background tasks, retries, or unauthorized use can produce traffic too. The correct response is attribution: connect the usage record to the process, session, model route, and request purpose.

This article treats warming as a measurable operating choice. The question is not whether background activity looks suspicious. It is whether a known feature provides enough benefit for your actual pauses between coding tasks.

The visible conversation is not a complete request ledger

A chat transcript shows the work a user sees. It may not show every request a client sends while maintaining a session. Therefore, counting visible assistant messages is not a reliable way to reconstruct model usage.

For a controlled investigation, record when you submit a normal task, when you stop interacting, and when the client resumes activity. Compare those timestamps with request records for the relevant credential and route.

Keep the model identifier and process identity in the record. If several terminals share one credential, an idle window in one terminal tells you little about the others. A separate test credential makes the experiment easier to interpret, provided the service supports creating one for your account.

If your current problem is an authentication failure rather than unexpected usage, use the OpenCode expired-key guide. If a replaced key still appears to be used, the stale-key investigation addresses configuration persistence. Those are different problems from deliberately enabled warming.

Inspect the effective configuration, not a remembered setting

A project file can differ from a user-level file. A running process can also differ from the file you just edited. Follow the OpenCode configuration documentation for the version you have installed and identify which configuration sources apply.

For an explicit disabled baseline, the documented setting is:

json
{
  "$schema": "https://opencode.ai/config.json",
  "warming": false
}

The current warming documentation also describes provider and model overrides. Review those when investigating behavior; a top-level setting alone may not describe the configuration you intended to evaluate.

Do not delete all configuration just to remove one feature. That can also change the model route, credential source, permissions, and agent behavior. Make one scoped change and retain a copy of the relevant configuration without secrets.

After applying the change, start a controlled session using the documented reload or restart procedure. Confirm the selected model. A new session with a different model is not a clean comparison with the old one.

A short idle experiment can answer the first question

Choose a small repository task with synthetic or approved code. Run it once, then stop interacting for a defined observation window. Record the window length and leave the application otherwise unchanged.

Observe whether additional requests appear. Record their timestamps and any explicit client log evidence of purpose. Do not classify a request as warming merely because its prompt contains a common word such as “OK.” User work and other maintenance actions can produce similar text.

Repeat the observation with warming disabled. If the extra requests disappear and the client logs agree, you have evidence connecting the feature to the traffic. If they remain, continue investigating other processes and features.

A test account or dedicated credential makes this comparison more useful, but it does not identify request purpose by itself. You still need the local session timeline or trustworthy client events. Avoid presenting a graph of all account traffic as proof about one terminal.

No model benchmark is needed for this first experiment. It answers a narrower operational question: whether idle requests in this setup correspond to the configured feature.

Label request purpose at collection time

When your application or log pipeline can identify request purpose reliably, preserve that label before aggregation. The following example summarizes a normalized ledger. It does not scrape OpenCode internals or guess a purpose from generated text.

python
from collections import defaultdict
from decimal import Decimal

def summarize_purposes(rows):
    groups = defaultdict(lambda: {
        "requests": 0, "known_cost": Decimal("0"), "missing_cost": 0
    })
    for row in rows:
        purpose = row.get("verified_purpose", "unknown")
        if purpose not in {"user", "warming", "unknown"}:
            purpose = "unknown"
        item = groups[purpose]
        item["requests"] += 1
        if row.get("cost") is None:
            item["missing_cost"] += 1
        else:
            item["known_cost"] += Decimal(str(row["cost"]))
    return {
        purpose: {**item, "known_cost": str(item["known_cost"])}
        for purpose, item in groups.items()
    }

if __name__ == "__main__":
    # Synthetic ledger; values are not provider or gateway prices.
    rows = [
        {"verified_purpose": "user", "cost": "0.04"},
        {"verified_purpose": "warming", "cost": "0.01"},
        {"verified_purpose": "warming", "cost": "0.01"},
        {"verified_purpose": "unknown", "cost": None},
    ]
    print(summarize_purposes(rows))

Keep unknown requests visible. Reclassifying them as zero-cost maintenance would hide the very uncertainty you need to resolve. Likewise, a missing charge is not a confirmed free request.

For a real ledger, retain the currency, settlement source, model route, and collection time. Deduplicate records before aggregation. If the gateway reports only aggregate usage, state that limitation instead of inventing per-request charges.

This example uses Python's Decimal type for monetary arithmetic. It does not calculate token charges because the applicable pricing contract belongs to the route and account being evaluated.

Warming is valuable only if later work benefits

Showing that warming creates requests is only half the analysis. Its purpose is to improve the state available when normal work resumes. Measure that later work as well.

Define a repeatable resumed task. Keep the repository revision, conversation setup, model route, and prompt consistent. Compare end-to-end completion time and accepted result quality between your enabled and disabled configurations.

Observe cache-related usage only when the service provides meaningful fields. If the response does not expose cache reads or writes, mark the cache effect as unobserved. A faster answer alone does not establish which internal mechanism caused the difference.

The existing Claude gateway cache-hit test provides a related measurement pattern for an appropriate route. The Gemini context-caching cost guide addresses a different provider contract. Neither should be treated as proof that all models preserve caches in the same way.

Use separate experiments for materially different model families. A cache-related setting useful for one model may be unnecessary or ineffective for another. The serving route also matters because request translation can affect what reaches the provider.

Compare complete work windows

Imagine an illustrative session where enabled warming adds 0.06 currency units during a pause and the resumed task costs 0.03 units less. On direct request charges alone, that window costs 0.03 units more. The extra expense might still be acceptable if the latency benefit matters, but it should be a conscious product choice.

Those values are invented arithmetic, not observations about OpenCode or any model. Replace them with settled costs from your own trial. Include failed warming attempts and resumed-task retries where they incur charges under your account terms.

A useful comparison covers the normal task before the pause, all known idle traffic, and the resumed task through acceptance. Comparing only the first request after a pause can make the enabled configuration appear cheaper by excluding the cost paid during the pause.

Also record how often users actually return within the relevant window. If a developer closes the laptop for the evening, preserving a short-lived state may provide no later benefit to that session. If users repeatedly pause for brief code reviews, the pattern may be different.

The decision can vary by workflow. An interactive coding team may value reduced wait time, while an unattended batch process may prefer predictable request volume. Avoid a global policy based on one developer's afternoon.

Investigate unexplained traffic without changing everything

If traffic remains after warming is disabled, inspect other running clients and scheduled jobs. Compare timestamps with retry logs and queue activity. Confirm that the account usage view is scoped to the expected credential or project.

Do not immediately rotate every key unless the evidence warrants that response. Rotation may be appropriate for suspected exposure, but it can also interrupt unrelated workloads and obscure which process generated the traffic.

The CI credential-rotation guide helps when a controlled rotation is required. For known rate-limit failures, the Codex retry-limit article offers a related example of separating error causes from repeated attempts. Its Codex-specific details do not describe OpenCode configuration.

Preserve enough evidence to explain your conclusion: effective settings, client version, model route, observation window, known request purposes, and any unknown usage. That record is more valuable than a broad claim that the client is either “wasteful” or “free while idle.”

Keep the observation window reproducible

Save the start and end times of each idle window alongside the configuration used. Record whether the machine slept, the network changed, or the process exited. Those events can interrupt an experiment and should not silently be interpreted as evidence that warming is cheaper or more effective.

Repeat a small number of comparable windows before changing a team-wide setting. One resumed request can be unusually fast or slow for reasons unrelated to cache state. Look for a consistent operational pattern while keeping the scope of the conclusion narrow.

Include a no-return window in the evaluation if users commonly abandon sessions. That window has maintenance activity but no resumed task from which to obtain a benefit. Excluding it can make a configuration look attractive for a work pattern the team does not actually have.

Document unknowns instead of filling them with assumptions. If request purpose cannot be verified or settlement data arrives later, leave the result provisional and update the ledger when the missing evidence becomes available.

Turn the finding into an operating policy

Document which workflows may enable warming, what benefit they are trying to obtain, and when the policy should be reviewed. A model change, a new pricing contract, or a different work pattern can alter the result.

Use the API gateway integration guide to keep the routing and credential layer explicit. If you want to evaluate this workflow through a gateway, register a 4SAPI account, confirm the selected model and protocol, and begin with a dedicated test session.

The first milestone is simple: account for the requests during one pause and the work that follows it. Once that window is explainable, you can decide whether warming deserves a place in the team's normal configuration.

Further documentation

Tags:OpenCodePrompt CachingAPI UsageModel CostsAPI Gateway

Recommended reading

Explore more frontier insights and industry know-how.