Start typing to search the documentation.

Docs navigation

Providers

OpenCode includes a built-in catalog of providers and models from models.dev. You can also add a custom provider to your configuration.

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "acme": {
      "name": "Acme",
      "env": ["ACME_API_KEY"],
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": {
        "baseURL": "https://llm.acme.example/v1",
      },
      "models": {
        "qwen3-coder": {
          "name": "Qwen 3 Coder",
        },
      },
    },
  },
}

The providers object is keyed by provider ID. Each provider accepts these fields:

FieldPurpose
nameDisplay name.
envOrdered environment variable names that provide a connection.
packageRuntime provider package.
settingsJSON settings passed to the runtime package, such as baseURL.
headersString-valued HTTP headers added to requests.
bodyJSON fields merged into request bodies.
modelsModels to add or override, keyed by catalog model ID.

OpenCode Go

OpenCode Go is an optional subscription that provides access to coding models tested by the OpenCode team. Subscribe in the console, copy your API key, then run /connect in the TUI and select OpenCode Go:

/connect

Paste your API key, then run /models to select a Go model. See the Go guide for setup, usage limits, endpoints, and privacy details.

Azure OpenAI and Microsoft Foundry

Azure supports either an API key or your existing Microsoft Entra ID session from the Azure CLI.

  1. Install the Azure CLI and sign in:

    az login

    If the resource belongs to another tenant or subscription, select them first:

    az login --tenant TENANT_ID
    az account set --subscription NAME_OR_ID
  2. Find your Azure resource name in the Azure portal or Microsoft Foundry: open the Azure OpenAI or Foundry resource and copy its Resource name. It is also the first part of the endpoint: my-models in https://my-models.openai.azure.com/ or https://my-models.services.ai.azure.com/.

    If your identity can list resources, the Azure CLI can display the names and resource groups:

    az cognitiveservices account list \
      --query "[].{name:name,resourceGroup:resourceGroup}" \
      --output table
  3. In OpenCode, run /connect, select Azure, and choose Microsoft Entra ID (Azure CLI). Enter the Azure resource name when prompted. If AZURE_RESOURCE_NAME is already set, OpenCode uses it without prompting.

  4. Select a deployed model with /models.

OpenCode does not query Azure management APIs or discover deployments. Select a model whose catalog name matches your deployment, or configure the deployment name explicitly:

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "azure": {
      "models": {
        "gpt-5-mini": {
          "modelID": "gpt-production",
        },
      },
    },
  },
}

Your identity needs the Cognitive Services OpenAI User role for Azure OpenAI models or the Cognitive Services User role for other Foundry models. If a request fails because the token belongs to another tenant, sign in again with az login --tenant TENANT_ID.

WebSocket transport

OpenAI, xAI, and supported Azure Responses models keep one WebSocket connection open per session and send each step over it instead of opening a new HTTP request. While the request prefix is unchanged, consecutive steps only transmit what was added since the previous response, which cuts upload volume on long sessions. OpenAI provider compaction runs over the same connection. xAI continues a chain only from stored responses, so with its default store: false each step is sent in full over the reused connection.

The connection is transparent. When the provider closes the socket, the next step reconnects; when a connection cannot be opened at all, the session continues over HTTP. Plugins that register http.request or http.response hooks for a provider keep it on HTTP so the hooks observe every request.

WebSockets are opt-in per built-in provider. Set websocket: true to enable a supported provider or model, or false to disable a built-in opt-in; a model policy overrides the provider policy:

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "openai": {
      "websocket": false,
      "models": {
        "gpt-5.5": { "websocket": true },
      },
    },
  },
}

Endpoint

Override settings.baseURL to send an existing provider through a proxy or compatible endpoint. Its existing package, models, and connection continue to apply:

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "anthropic": {
      "settings": {
        "baseURL": "https://llm-proxy.example.com/anthropic",
      },
    },
  },
}

settings is package-specific. A field only has an effect when the selected package supports it.

Headers and body

Use headers to add HTTP headers to provider requests. Use body to merge additional JSON fields into each request body:

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "openai": {
      "headers": {
        "X-Gateway-Tenant": "engineering",
      },
      "body": {
        "metadata": {
          "application": "opencode",
        },
      },
    },
  },
}

Package

The package field selects the runtime used to communicate with a provider. For an OpenAI-compatible API, use the built-in compatible package:

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "acme": {
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": {
        "baseURL": "https://llm.acme.example/v1",
      },
      "models": {
        "qwen3-coder": {
          "name": "Qwen 3 Coder",
        },
      },
    },
  },
}

Native package options:

  • @opencode/ai/providers/openai
  • @opencode/ai/providers/openai/chat
  • @opencode/ai/providers/openai/responses
  • @opencode/ai/providers/openai-compatible
  • @opencode/ai/providers/openai-compatible/responses
  • @opencode/ai/providers/anthropic
  • @opencode/ai/providers/anthropic-compatible
  • @opencode/ai/providers/google
  • @opencode/ai/providers/google-vertex
  • @opencode/ai/providers/google-vertex/gemini
  • @opencode/ai/providers/google-vertex/chat
  • @opencode/ai/providers/google-vertex/responses
  • @opencode/ai/providers/google-vertex/messages
  • @opencode/ai/providers/azure
  • @opencode/ai/providers/azure/chat
  • @opencode/ai/providers/azure/responses
  • @opencode/ai/providers/amazon-bedrock
  • @opencode/ai/providers/amazon-bedrock/mantle
  • @opencode/ai/providers/amazon-bedrock/mantle/chat
  • @opencode/ai/providers/amazon-bedrock/mantle/responses
  • @opencode/ai/providers/openrouter
  • @opencode/ai/providers/xai

You can also use an npm package such as @acme/opencode-provider or an absolute file:// URL for a local package.

Use settings for options supported by the selected package.

Models

Add a model under a provider’s models map. The object key is the model ID used in OpenCode; modelID is the ID sent to the provider:

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "model": "openai/coding",
  "providers": {
    "openai": {
      "models": {
        "coding": {
          "modelID": "gpt-5.2",
          "name": "GPT-5.2 Coding",
        },
      },
    },
  },
}

See Models for model selection, defaults, capabilities, limits, costs, and variants.