OpenCode
OpenCode
OpenCode
Prepare
Use a gateway root, a virtual key with model access and a public model name. Test GET /v1/models first.
Configure
Add this custom provider to opencode.json, export XHUB_API_KEY, restart and choose xhub/YOUR_MODEL_NAME. The OpenAI compatible adapter uses Chat completions.
Verify and troubleshoot
Send “Hello, introduce yourself.” and inspect the call ID in XHub request logs. Verify streaming, tool calls and images separately against deployment capabilities. For 401 check the virtual key; for 403 check model scope; for 404 check the URL and duplicated /v1. Client settings vary by version.
Request example
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"xhub": {
"npm": "@ai-sdk/openai-compatible",
"name": "XHub",
"options": {
"baseURL": "http://localhost:4000",
"apiKey": "{env:XHUB_API_KEY}"
},
"models": {
"YOUR_MODEL_NAME": {
"name": "YOUR_MODEL_NAME"
}
}
}
}
}