[FEATURE]: Add option to disable models.dev fetch for corporate proxy environments #3239

Open
opened 2026-02-16 17:39:16 -05:00 by yindo · 9 comments
Owner

Originally created by @emvnuel on GitHub (Dec 1, 2025).

Originally assigned to: @thdxr on GitHub.

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Problem

Users behind corporate proxies experience issues with OpenCode 1.x.x versions due to a network call made on startup to https://models.dev/api.json. This call happens unconditionally and does not respect HTTP_PROXY/HTTPS_PROXY environment variables since Bun's native fetch() doesn't automatically handle proxy configuration.

Version 0.15.31 worked fine because this fetch behavior was either not present or handled differently.

Current Behavior

In packages/opencode/src/provider/models.ts, the get() function always calls refresh() which makes a network request:

export async function get() {
  refresh()  // Always calls fetch to models.dev
  const file = Bun.file(filepath)
  const result = await file.json().catch(() => {})
  if (result) return result as Record<string, Provider>
  const json = await data()
  return JSON.parse(json) as Record<string, Provider>
}

The code does have fallback mechanisms (local cache + bundled data), but the fetch is attempted regardless.

Proposed Solution

Add a configuration option to disable network calls, e.g.:

{
  "offline": true
}

Or more granularly:

{
  "experimental": {
    "disable_models_fetch": true
  }
}

When enabled, OpenCode would skip the models.dev fetch and rely on:

  1. Cached data at ~/.cache/opencode/models.json
  2. Bundled model data (compiled via macro)

Workaround

Currently, users can whitelist models.dev in their corporate proxy, but this isn't always possible in restricted environments.

Environment

  • OpenCode version: 1.x.x (works in 0.15.31)
  • Issue: Corporate proxy blocking/timing out on models.dev fetch
Originally created by @emvnuel on GitHub (Dec 1, 2025). Originally assigned to: @thdxr on GitHub. ### Feature hasn't been suggested before. - [x] I have verified this feature I'm about to request hasn't been suggested before. ### Describe the enhancement you want to request ### Problem Users behind corporate proxies experience issues with OpenCode 1.x.x versions due to a network call made on startup to `https://models.dev/api.json`. This call happens unconditionally and does not respect `HTTP_PROXY`/`HTTPS_PROXY` environment variables since Bun's native `fetch()` doesn't automatically handle proxy configuration. Version 0.15.31 worked fine because this fetch behavior was either not present or handled differently. ### Current Behavior In `packages/opencode/src/provider/models.ts`, the `get()` function always calls `refresh()` which makes a network request: ```typescript export async function get() { refresh() // Always calls fetch to models.dev const file = Bun.file(filepath) const result = await file.json().catch(() => {}) if (result) return result as Record<string, Provider> const json = await data() return JSON.parse(json) as Record<string, Provider> } ``` The code does have fallback mechanisms (local cache + bundled data), but the fetch is attempted regardless. ### Proposed Solution Add a configuration option to disable network calls, e.g.: ```jsonc { "offline": true } ``` Or more granularly: ```jsonc { "experimental": { "disable_models_fetch": true } } ``` When enabled, OpenCode would skip the `models.dev` fetch and rely on: 1. Cached data at `~/.cache/opencode/models.json` 2. Bundled model data (compiled via macro) ### Workaround Currently, users can whitelist `models.dev` in their corporate proxy, but this isn't always possible in restricted environments. ### Environment - OpenCode version: 1.x.x (works in 0.15.31) - Issue: Corporate proxy blocking/timing out on `models.dev` fetch
yindo added the discussion label 2026-02-16 17:39:16 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 1, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #531: Support HTTP_PROXY & HTTPS_PROXY for users behind firewalls and corporate proxies
  • #3989: acp-command unhandled rejection when http_proxy is set (similar crash behavior in 1.x.x)
  • #4284: Socket connection error with ProxyChains from v1.0.0 (proxy-related networking issues)
  • #3053: Stuck After Compaction with long calls to models.dev (related to models.dev fetch blocking)
  • #2224: Support for airgapped installation (offline environment support)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Dec 1, 2025): This issue might be a duplicate of existing issues. Please check: - #531: Support HTTP_PROXY & HTTPS_PROXY for users behind firewalls and corporate proxies - #3989: acp-command unhandled rejection when http_proxy is set (similar crash behavior in 1.x.x) - #4284: Socket connection error with ProxyChains from v1.0.0 (proxy-related networking issues) - #3053: Stuck After Compaction with long calls to models.dev (related to models.dev fetch blocking) - #2224: Support for airgapped installation (offline environment support) Feel free to ignore if none of these address your specific case.
Author
Owner

@thdxr commented on GitHub (Dec 1, 2025):

yep this is a good idea i was toying around with it

@thdxr commented on GitHub (Dec 1, 2025): yep this is a good idea i was toying around with it
Author
Owner

@ariane-emory commented on GitHub (Dec 2, 2025):

I think experimental.skip_models_fetch would be a better name. After all, we're not trying to disable the ability to fetch updated model lists (opencode models --refresh should keep working), we're just trying to skip the automatic fetching of the updated list.

@ariane-emory commented on GitHub (Dec 2, 2025): I think `experimental.skip_models_fetch` would be a better name. After all, we're not trying to disable the _ability_ to fetch updated model lists (`opencode models --refresh` should keep working), we're just trying to skip the automatic fetching of the updated list.
Author
Owner

@ariane-emory commented on GitHub (Dec 4, 2025):

We might be able to achieve this simply by not enabling the 60 minute model refresh timer when experimental.skip_models_fetch == true? Need to look into how viable that is, but it sounds like it could work.

@ariane-emory commented on GitHub (Dec 4, 2025): We might be able to achieve this simply by not enabling the 60 minute model refresh timer when `experimental.skip_models_fetch == true`? Need to look into how viable that is, but it sounds like it could work.
Author
Owner

@BAMSHK commented on GitHub (Jan 15, 2026):

Image 在有网的机器访问https://[models.dev/api.json](https://models.dev/api.json)网站下载json 存放到上述目录下文件中之后 可以正常启动opencode了
@BAMSHK commented on GitHub (Jan 15, 2026): <img width="690" height="342" alt="Image" src="https://github.com/user-attachments/assets/6faa2809-c248-4e4b-99f8-40f4f03e7d9a" /> 在有网的机器访问https://[models.dev/api.json](https://models.dev/api.json)网站下载json 存放到上述目录下文件中之后 可以正常启动opencode了
Author
Owner

@b3nw commented on GitHub (Jan 17, 2026):

I looked into this and found out why OPENCODE_DISABLE_MODELS_FETCH doesn't work - I think it's basically broken by design?

The problem

In models.ts, the get() function does this:

export async function get() {
  refresh()  // flag stops this from fetching
  const result = await file.json().catch(() => {})
  if (result) return result  // but it still reads the cache...
  if (typeof data === "function") {
    return JSON.parse(await data())  // ...or falls back to baked-in data
  }
  // last resort: fetch
}

So even if you:

  1. Set the flag
  2. Delete the cache file
    ...it still loads models from a Bun macro that embeds models.dev at build time. The data is literally compiled into the binary. There's no escaping it.

Proposed fixes

Option A: Make the env var actually work (easy fix)
Just return empty when the flag is set:

export async function get() {
  if (Flag.OPENCODE_DISABLE_MODELS_FETCH) return {}
  // ... rest unchanged
}

Should I submit a PR to fix this? or is this intentional and a different solution should be added?

@b3nw commented on GitHub (Jan 17, 2026): I looked into this and found out why `OPENCODE_DISABLE_MODELS_FETCH` doesn't work - I think it's basically broken by design? ### The problem In `models.ts`, the `get()` function does this: ```typescript export async function get() { refresh() // flag stops this from fetching const result = await file.json().catch(() => {}) if (result) return result // but it still reads the cache... if (typeof data === "function") { return JSON.parse(await data()) // ...or falls back to baked-in data } // last resort: fetch } ``` So even if you: 1. Set the flag 2. Delete the cache file ...it still loads models from a **Bun macro that embeds models.dev at build time**. The data is literally compiled into the binary. There's no escaping it. ### Proposed fixes **Option A: Make the env var actually work (easy fix)** Just return empty when the flag is set: ```typescript export async function get() { if (Flag.OPENCODE_DISABLE_MODELS_FETCH) return {} // ... rest unchanged } ``` Should I submit a PR to fix this? or is this intentional and a different solution should be added?
Author
Owner

@junmediatek commented on GitHub (Jan 18, 2026):

@thdxr @rekram1-node

Could you help to check this issue?
https://github.com/Latitudes-Dev/shuvcode/pull/307

@junmediatek commented on GitHub (Jan 18, 2026): @thdxr @rekram1-node Could you help to check this issue? https://github.com/Latitudes-Dev/shuvcode/pull/307
Author
Owner

@OneOfLzx commented on GitHub (Jan 22, 2026):

You might consider trying the OpenCode Sentinel project—it cuts all network access except to your LLM, so it works flawlessly in network-restricted environments👍👍.

Repo: https://github.com/oneoflzx/opencode-sentinel

@OneOfLzx commented on GitHub (Jan 22, 2026): You might consider trying the **OpenCode Sentinel** project—it cuts all network access **except** to your LLM, so it works flawlessly in **network-restricted environments**👍👍. Repo: https://github.com/oneoflzx/opencode-sentinel
Author
Owner

@haplo commented on GitHub (Feb 3, 2026):

I stumbled upon this issue with my own use case: I'm trying to sandbox opencode restricting it to only localhost Ollama for projects with personal data, but it fails because of the mandatory models.dev download. It would be nice to make it optional, or to skip it if the user provides a specific model to use.

@haplo commented on GitHub (Feb 3, 2026): I stumbled upon this issue with my own use case: I'm trying to sandbox opencode restricting it to only localhost Ollama for projects with personal data, but it fails because of the mandatory models.dev download. It would be nice to make it optional, or to skip it if the user provides a specific model to use.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3239