8000 Read custom providers from `opencode.json` from central `~/.config/opencode/` config instead of root of each project · Issue #152 · sst/opencode · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Read custom providers from opencode.json from central ~/.config/opencode/ config instead of root of each project #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GitMurf opened this issue Jun 16, 2025 · 7 comments
Assignees

Comments

@GitMurf
Copy link
GitMurf commented Jun 16, 2025

@thdxr I followed the instructions from the readme for custom options for a openai compatible provider (as you pointed to in your readme) and that works when I add it to a opencode.json file in the root of a project. But I want to be able to use it for all projects but cannot seem to get it to read it from ~/.config/opencode/ or from ~ (home) or from ~/.opencode/ etc... I tried all the potential opencode config locations with no luck.

Am I doing something wrong or do I need to copy the custom opencode.json to each of my project locations in every place I want to use OpenCode with my custom provider options?

Thanks!!

Originally posted by @GitMurf in #140

Figured easier for you all to track @thdxr if I open a new issue for this. Thanks!

p.s. I have dev repo pulled locally and seeing your minute by minute pushes ;) so whenever you are ready for me to test and I fetch and pull and confirm if working!

@GitMurf
Copy link
Author
GitMurf commented Jun 16, 2025

Similar issue opened here #153 (closed to consolidate here)

@thdxr
Copy link
Collaborator
thdxr commented Jun 17, 2025

yep im going to implement this - my idea was letting you mirror the same structure as models.dev inside ~/.config/opencode/providers

does that work for you?

https://github.com/sst/models.dev/tree/dev/providers

@GitMurf
Copy link
Author
GitMurf commented Jun 17, 2025

does that work for you?

@thdxr I was actually thinking of requesting exactly that but thought it may sound too complicated 🤣 Perfect!

One additional note, I have my OpenAI api key set as env variable for other tools, but I don't want it to show up in the model chooser for opencode. In previous "go version" of opencode we could explicitly disable providers. Is there a way you could implement that? I only want specific providers to show up when using /model but if OpenAI api key env variable is set, opencode seems to auto "load it". Not a huge deal, but would be nice if this was possible!

Copy link
Collaborator
thdxr commented Jun 17, 2025

good idea can you make a seperate issue for that

@GitMurf
Copy link
Author
GitMurf commented Jun 17, 2025

good idea can you make a seperate issue for that

@thdxr see #157

@thdxr thdxr self-assigned this Jun 17, 2025
Copy link
Collaborator
thdxr commented Jun 17, 2025

implemented in 0.1.72 and updated README

@thdxr thdxr closed this as completed Jun 17, 2025
@GitMurf
Copy link
Author
GitMurf commented Jun 18, 2025

@thdxr the new providers config setup inside of ~/.config/opencode/providers/... works well except for one part. It does not have a way to pass in options like the baseURL for proxying / openai compatible custom providers.

I don't know if there is a better way, but here is the patch that got it working for me if I have a provider.toml like this:

name = "GitHub Copilot"
npm = "@ai-sdk/openai-compatible"

[options]
baseURL = "http://localhost:3000"

Here is the patch that fixes it:

diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts
index c155891..1121a0b 100644
--- a/packages/opencode/src/provider/provider.ts
+++ b/packages/opencode/src/provider/provider.ts
@@ -150,6 +150,7 @@ export namespace Provider {
         name: provider.name ?? existing?.name ?? providerID,
         env: provider.env ?? existing?.env ?? [],
         models: existing?.models ?? {},
+        ...(provider.options ? { options: provider.options } : {}),
       }
 
       for (const [modelID, model] of Object.entries(provider.models ?? {})) {
@@ -178,6 +179,12 @@ export namespace Provider {
       database[providerID] = parsed
     }
 
+    for (const [providerID, provider] of Object.entries(database)) {
+      if ("options" in provider && provider.options) {
+        mergeProvider(providerID, provider.options, "config")
+      }
+    }
+
     const disabled = await GlobalConfig.get().then(
       (cfg) => new Set(cfg.disabled_providers ?? []),
     )

Let me know if you have any questions or thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0