Skip to content

Add a Custom Provider to OpenCode

Add an unlisted OpenAI-compatible provider to OpenCode, define its base URL and models, store its API key, and troubleshoot provider configuration.

MGMCSA Guru Team August 1, 2026 2 min read
OpenCode configuration defining a custom API provider

OpenCode includes built-in connections for many providers. Check /connect before writing configuration. A custom provider is useful for an unlisted service, a local server, or an organization gateway.

Store the credential

Inside OpenCode, run /connect, choose Other, and enter a provider ID. Use a short stable value such as mygateway, then enter the API key. The ID must match the configuration block.

Add the provider configuration

For a Chat Completions-compatible endpoint, the current OpenCode schema uses this pattern:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "mygateway": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "My gateway",
      "options": {
        "baseURL": "https://api.example.com/v1"
      },
      "models": {
        "provider-model-id": {
          "name": "Provider model"
        }
      }
    }
  }
}

Replace the provider ID, URL, and model ID. Do not use the example values in a live configuration.

Custom provider fields

provider ID Matches the ID created through /connect
npm Protocol adapter used for the endpoint
baseURL Provider or gateway API URL
models Exact model IDs exposed by the endpoint

Select and test the model

Restart OpenCode if the new provider does not appear, then run:

/models

Select the custom model and send a read-only request. Check the provider logs before approving file changes.

Common problems

  • Provider not found: the ID from /connect does not match the configuration key.
  • Model not found: the models map contains a display name instead of the API model ID.
  • Authentication failure: reconnect the provider and confirm the key belongs to the configured endpoint.
  • Format error: the endpoint and selected AI SDK package use different protocols.
  • Built-in provider duplicated: remove the custom block and use the standard /connect entry.

Custom OpenCode provider checklist

  • Built-in provider list checked first
  • Credential stored with /connect and Other
  • Provider ID matched in configuration
  • Endpoint protocol verified
  • Exact model ID added
  • Read-only request confirmed in provider logs

Frequently asked questions

When do I need a custom provider?

Use one when the service is not listed under /connect or when your organization uses a custom gateway or base URL. Built-in providers are simpler for standard services.

How do I store the API key?

Run /connect, choose Other, create a memorable provider ID, and enter the key. The same provider ID must be used in your OpenCode configuration.

Which package handles OpenAI-compatible APIs?

Current OpenCode documentation uses @ai-sdk/openai-compatible for custom Chat Completions endpoints. A Responses endpoint may require a different package, so match the provider protocol.

How do I select the custom model?

Add exact API model IDs under the provider's models map, restart OpenCode if needed, then run /models.

Sources & further reading

Official vendor documentation referenced while writing this guide.

MG

MCSA Guru Team

IT & Systems Administration

We are working IT pros and system administrators who spend our days in Windows Server, Microsoft 365, and the wider Microsoft stack. MCSA Guru is where we write down the fixes and walkthroughs we wish we had found the first time.

MCSA Guru provides independent, educational IT guidance. Microsoft, Windows, Windows Server, Microsoft 365, Exchange, and Microsoft Teams are trademarks of Microsoft Corporation; Docker is a trademark of Docker, Inc. MCSA Guru is not affiliated with or endorsed by Microsoft or Docker. Always test changes in a safe environment before applying them in production.

Related guides

Fixing something right now?

Jump straight into the guide library or search for the exact error or task you are dealing with.