Skip to content

[Bug] Adding a custom provider always fails: "Integration not found: <provider-id>" #4038

Closed

Description

@chenyuhao0628

Steps to reproduce

  1. OpenChamber Desktop 2.0.2, macOS (Apple Silicon), using the bundled OpenCode CLI
  2. Settings → Providers → "Other / Custom"
  3. Fill in a custom provider — e.g. Provider ID commandcode, protocol openai-chat, display name commandcode, base URL https://api.commandcode.ai/provider/v1, API key set
  4. Save

What you expected

The custom provider is written into the OpenCode config (as the form description says) and becomes selectable in chat.

What happened instead

A toast appears: Integration not found: commandcode, and the provider is not saved. This reproduces with any custom provider ID (renaming the ID does not help).

Analysis (from the public sources — please confirm)

The save flow appears to store the API key through OpenCode's integration credential API. In the OpenCode v2 sources:

  • Integration.connection.key (packages/core/src/integration.ts) requires a registered integration with that exact ID, and dies with Key method not found: <id> otherwise.
  • Key methods are only registered for providers that exist in the models.dev catalog (packages/core/src/plugin/models-dev.ts registers key/env methods per catalog entry), plus a few plugin-defined integrations (openai, opencode, ...).
  • A brand-new custom provider ID is by definition not in models.dev, so this call can never succeed for the custom-provider form. (I verified the provider I tried is not in the models.dev catalog either — but any made-up ID should reproduce.)

Workaround

Hand-editing ~/.config/opencode/opencode.json works as expected:

{
  "provider": {
    "<id>": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "...",
      "options": { "baseURL": "...", "apiKey": "..." },
      "models": { "<model-id>": {} }
    }
  }
}

So the bug is limited to the UI save path — presumably the key should be written into the config (or via the legacy auth.set endpoint, which is what the official OpenCode desktop dialog does) for custom providers, instead of the integration-key endpoint.

Environment

  • OpenChamber Desktop 2.0.2, macOS Apple Silicon
  • Bundled OpenCode CLI (v2 line — not separately upgradeable from inside the desktop app)

Happy to paste openchamber status output if useful.

Activity

  1. openchamber-bot commented on Sep 26, 2026

    @openchamber-bot
    Contributor

    For the maintainer: fix-ready — cause traced

    Your analysis is right. The save flow in handleSaveCustomProvider (packages/ui/src/components/sections/providers/ProvidersPage.tsx:489-492) calls integration.connect.key with the custom provider ID before attempting the config write. OpenCode's integration.connect.key endpoint rejects any ID not present in its models.dev catalog, so this call always fails for custom providers and the config write at line 502 never executes.

    The config write path (PUT /api/provider → upsertProviderConfig) is designed for this — it writes provider blocks into opencode.json — but the API key is a separate concern: upsertProviderConfig explicitly does not write secrets (packages/web/server/lib/opencode/providers.js:203). The escape-suite tests already work around this by writing credentials directly into the SQLite credential table (packages/web/server/lib/spaces/places/escape-suite.js:219-224), confirming no OpenCode API route supports key storage for non-catalog integrations.

    Plausible-but-unconfirmed for the reporter: the fix path would be to either (a) skip integration.connect.key for custom providers entirely and store the API key via a new server-side route that writes to the SQLite credential table, or (b) embed the key into the provider config block itself (the options.apiKey path in the workaround). Either way, buildIntegrationKeyRequest at custom-provider-form.ts:622 should return null for custom provider IDs, and the credential storage should use a path that does not depend on the integration catalog.

    The upstream OpenCode issue anomalyco/opencode#51527 tracks the API-level gap. This issue stays here because the OpenChamber save flow is what triggers the failing call and the fix lives in OpenChamber.

    Minimal reproduction sketch

    The call chain:

    1. User fills custom provider form → validateCustomProvider() builds CustomProviderPersistPlan with literal apiKey
    2. buildIntegrationKeyRequest(plan) returns { integrationID: "my-custom", key: "sk-..." } (not null)
    3. integration.connect.key(keyRequest) throws Integration not found: my-custom
    4. Config write at runtimeFetch("/api/provider", ...) never runs

    No script needed — any custom provider ID with a literal API key reproduces this on current main.

  2. added
    bugSomething isn't working
    root-cause:foundBot traced a concrete code-level cause (not yet confirmed by the reporter)
    area:settingsSettings UI, config, preferences
    area:providersModel providers, API keys, model selection
    on Sep 26, 2026
  3. btriapitsyn commented on Sep 27, 2026

    @btriapitsyn
    Collaborator

    Fixed by 50766fa: the provider config is now written first and the key right after it, since OpenCode 2 only accepts a key for a custom provider once it's in config. The server also stopped asking for the old auth.json entry. Ships in 2.0.3; if saving still fails there, comment and we'll reopen.

  4. added a commit that references this issue on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providersModel providers, API keys, model selectionarea:settingsSettings UI, config, preferencesbugSomething isn't workingroot-cause:foundBot traced a concrete code-level cause (not yet confirmed by the reporter)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions