页面简介
Connect OpenCode to model providers such as OpenCode Go, ChatGPT, Amazon Bedrock, Google Vertex, GitHub Copilot, and Ollama, or add a custom one.
正文摘录
ProvidersOpenCode includes a provider and model catalog from models.dev. For most providers, connect an account first, then select a model. Setup Run /connect, choose a provider, and enter its credentials. Then run /models to select one of its models. /connect /models Go OpenCode Go is an optional subscription for coding models tested by the OpenCode team. Subscribe in the console, then connect your OpenCode account. /connect # Select OpenCode, then sign in with your OpenCode account. /models See the Go guide for usage limits, endpoints, and privacy details. ChatGPT Use a ChatGPT Plus or Pro plan instead of an OpenAI API key. Connect OpenAI, then choose Sign in with ChatGPT or one of the legacy Codex sign-in methods. Usage counts against your plan, so these models show no cost. /connect /models Context limits By default, OpenCode caps the context window for these sign-ins below each model’s real limit. The caps match the defaults in Codex, so your plan usage is consumed at a similar rate as it would be in other OpenAI products. ModelInput limitGPT-6.1 Sol and newer500,000Older models272,000 To opt out, disable the cap plugin in your config. The - prefix turns off a built-in plugin; all other plugins stay enabled. opencode.jsonc{ "plugins": ["-opencode.provider.openai-context-caps"], } Claude Agent Use your Claude plan or another Claude Code login. Claude Agent runs Claude Code on your machine, so install Claude Code 2.1.248 or later and sign in first. Terminalclaude auth login Then connect Claude Agent and choose a model. The model list comes from Claude Code. Effort levels are variants, such as claude-agent/opus#high. /connect # Select Claude Agent. /models See Claude Agent for details. Custom Add a provider when its API is not already in the catalog. This OpenAI-compatible example defines the credential, runtime package, endpoint, and first model together. 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 the provider ID used in model references, such as acme/qwen3-coder. FieldPurposenameDisplay name.envOrdered environment variable names that can provide the credential.packageRuntime provider package.canonicalBuilt-in provider ID whose catalog defaults this provider inherits.compatibilityAPI quirks shared by every model of this provider. See Compatibility.settingsTyped OpenCode controls and JSON options passed to the runtime package.headersString-valued HTTP headers added to requests.bodyJSON fields merged into request bodies.modelsModels to add or override, keyed by the OpenCode model ID. Endpoint Override settings.baseURL to send a catalog provider through a proxy or compatible endpoint. Its existing package, models, and connection still 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. Requests Use headers for additional HTTP headers and body for JSON fields that should be merged into every request body. opencode.jsonc{ "$schema": "https://opencode.ai/config.json", "providers": { "openai": { "headers": { "X-Gateway-Tenant": "engineering", }, "body": { "metadata": { "application": "opencode", }, }, }, }, } Both fields can also be set on a model or variant when only part of a provider’s traffic needs the override. opencode.jsonc{ "$schema": "https://opencode.ai/config.json", "providers": { "openai": { "models": { "gpt-6.1-sol": { "headers": { "X-Model-Tier": "coding" }, "variants": [ { "id": "batch", "body": { "service_tier": "flex" }, }, ], }, }, }, }, } Timeouts HTTP requests wait up to five minutes for response headers (ten minutes for Gemini and DeepSeek models) and up to fifteen minutes between streamed response chunks. Set the provider’s settings.headerTimeout or settings.chunkTimeout to a number of milliseconds to change a limit, or to false to disable it. settings.timeout additionally bounds the whole request from send until the response completes; it has no default. These configuration settings apply provider-wide, not per model or variant. On a WebSocket transport, chunkTimeout bounds the gap between frames instead and defaults to thirty minutes. opencode.jsonc{ "$schema": "https://opencode.ai/config.json", "providers": { "anthropic": { "settings": { "headerTimeout": 600000, "chunkTimeout": false, }, }, }, } A request that exceeds either limit fails with a transport error. OpenCode retries a timed-out request up to three times before giving up. Request encoding settings.encoding compresses HTTP request bodies with "zstd" or "gzip", or sends plain JSON with "none". Set it on a provider, model, or variant; the most specific value wins. Only enable an encoding the endpoint decodes: most providers and gateways reject compressed bodies. OpenAI defaults to "zstd" when signed in with ChatGPT and no custom baseURL is configured; API keys send plain JSON. WebSocket messages are unaffected. opencode.jsonc{ "$schema": "https://opencode.ai/config.json", "providers": { "openai": { "settings": { "encoding": "none" }, }, }, } Packages The package field selects the runtime that communicates with a provider. Use the compatible runtime for APIs that implement the OpenAI request format. 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": {}, }, }, }, } Native package options include: @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/messages @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. opencode.jsonc{ "$schema": "https://opencode.ai/config.json", "providers": { "acme": { "package": "@acme/opencode-provider", "models": { "acme-coder": {} }, }, }, } Models Add or override models in a provider’s models map. The map key is the model ID used by OpenCode; modelID changes the ID sent to the provider. opencode.jsonc{ "$schema": "https://opencode.ai/config.json", "model": "openai/coding", "providers": { "openai": { "models": { "coding": { "modelID": "gpt-6.1-sol", "name": "GPT-6.1 Sol Coding", }, }, }, }, } FieldPurposemodelIDModel or deployment ID sent to the provider.nameDisplay name.familyModel family used for grouping related models.typeWhat the model produces: chat, decision, image, video, realtime, embedding or transcription. Defaults to chat; only chat models are offered for sessions. Realtime models that answer in speech are offered for voice, and set to disabled: true they aren’t.releaseDateRelease date as YYYY-MM-DD or YYYY-MM.packageRuntime override for this model. A transcription model names its transcription protocol, such as @opencode/ai/protocols/openai-transcription; a realtime model takes none, since voice sessions start through its API.settingsModel-level OpenCode controls and package-specific JSON settings.headersAdditional string-valued request headers.bodyAdditional JSON request body fields.capabilitiesTool support, accepted input and output media types, temperature support, and reasoning controls.compatibilityAPI quirks for this model, overriding the provider’s. See Compatibility.variantsNamed variants with their own settings, headers, and body.costInput, output, and optional cache pricing per million tokens.limitContext, input, and output token limits.disabledRemoves the model from selection when true. See Models for selection, defaults, capabilities, limits, costs, and variants. Azure Azure’s standard catalog endpoint needs a resource name in addition to its credential. Set settings.resourceName once, then connect an API key or use the Microsoft Entra ID session from the Azure CLI as described in Provider accounts. opencode.jsonc{ "$schema": "https://opencode.ai/config.json", "providers": { "azure": { "settings": { "resourceName": "my-models", }, }, }, } Find the Resource name in the Azure portal or Microsoft Foundry. It is also the first part of endpoints such as https://my-models.openai.azure.com/ and https://my-models.services.ai.azure.com/. Terminalaz cognitiveservices account list \ --query "[].{name:name,resourceGroup:resourceGroup}" \ --output table To use Entra ID, install the Azure CLI, sign in, then choose Microsoft Entra ID (Azure CLI) when connecting Azure. Terminalaz login Enter the resource name when connecting if it is not already supplied by configuration or the environment. A resource name saved with a connection takes precedence over configuration; connect again to change it. Azure CLI connections use the account selected in the Azure CLI. For a resource in another tenant or subscription, select both explicitly. Terminalaz login --tenant TENANT_ID az account set --subscription NAME_OR_ID I