Skip to Content
ModelWorks logoModelWorks
AdaptorsOpenAI SSE Adaptor

Connect OpenCode

Route OpenCode to any ModelWorks circuit as a custom model provider via the OpenAI SSE adaptor.

Connect OpenCode to ModelWorks

OpenCode is a terminal AI coding agent with 229K+ GitHub stars. This guide shows you how to connect OpenCode to any circuit on ModelWorks as a custom model provider.

Prerequisites

Step 1: Get your adaptor URL

Every circuit with an OpenAI SSE adaptor exposes a URL like:

Text
https://modelworks.ai/api/circuit-adaptors/ca-xxxxxxxxxxxxxxxxx/query

Find it on the circuit page under Adaptors → OpenAI SSE, or via the API:

Bash
curl https://modelworks.ai/api/circuit-adaptors/by-circuit-version/{version_uid} \
  -H "Authorization: Bearer mw_YOUR_API_KEY"

Step 2: Configure OpenCode

Add a custom provider to your opencode.json config file:

JSON
{
  "provider": {
    "modelworks-glm53": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "ModelWorks GLM-53",
      "options": {
        "baseURL": "https://modelworks.ai/api/circuit-adaptors/ca-xxxxxxxxx/query",
        "apiKey": "mw_YOUR_API_KEY"
      },
      "models": {
        "glm-53-abliterated": {
          "name": "GLM-53 Abliterated"
        }
      }
    }
  }
}

Step 3: Run your first circuit

Launch OpenCode and select the custom model:

Bash
opencode -m modelworks-glm53/glm-53-abliterated

Type a prompt. The circuit runs on ModelWorks and the response streams back to OpenCode.

Connecting via MCP

OpenCode also supports MCP. Add the ModelWorks xMCP server to your config:

JSON
{
  "mcp": {
    "modelworks": {
      "url": "https://modelworks.ai/.well-known/x.mcp",
      "auth": "bearer"
    }
  }
}

See Connect OpenCode via xMCP for the full MCP guide.

Troubleshooting

IssueFix
401 UnauthorizedYour API key expired. Generate a new one from Settings → Security Tokens.
402 Payment RequiredYour wallet needs credits. Fund it at modelworks.ai/settings/wallet, or use x402 pay-per-call.
TimeoutSome circuits take longer on first run. Retry.
No responseVerify the adaptor URL is correct — it must end with /query.
On this page

On this page

© 2026 ModelWorks. All rights reserved.