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
- OpenCode installed
- A ModelWorks account — sign up
- A ModelWorks API key — generated during onboarding or from Settings → Security Tokens
Step 1: Get your adaptor URL
Every circuit with an OpenAI SSE adaptor exposes a URL like:
https://modelworks.ai/api/circuit-adaptors/ca-xxxxxxxxxxxxxxxxx/queryFind it on the circuit page under Adaptors → OpenAI SSE, or via the API:
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:
{
"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:
opencode -m modelworks-glm53/glm-53-abliteratedType 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:
{
"mcp": {
"modelworks": {
"url": "https://modelworks.ai/.well-known/x.mcp",
"auth": "bearer"
}
}
}See Connect OpenCode via xMCP for the full MCP guide.
Troubleshooting
| Issue | Fix |
|---|---|
| 401 Unauthorized | Your API key expired. Generate a new one from Settings → Security Tokens. |
| 402 Payment Required | Your wallet needs credits. Fund it at modelworks.ai/settings/wallet, or use x402 pay-per-call. |
| Timeout | Some circuits take longer on first run. Retry. |
| No response | Verify the adaptor URL is correct — it must end with /query. |