OpenCode Integration
Connect OpenCode to Halfbill and verify a coding task.
OpenCode is an open-source coding agent for your terminal, desktop, and editor. Halfbill is a built-in provider, with usage tracked in your Halfbill dashboard.
Install
Use the OpenCode download page for your platform, or install the CLI:
pnpm add -g opencode-ai
opencode --versionConnect your API key
Start OpenCode in your project:
opencodeRun /connect, search for Halfbill, and enter a key from your Halfbill dashboard. OpenCode saves credentials for later sessions.
Open /models to choose a model. Browse the catalogue for current capabilities and pricing.
Using Halfbill Code? A Halfbill Code plan key works the same way. Select a canonical model ID such as
claude-sonnet-5.
Configure with an environment variable
For scripts or a project-specific configuration, set your key:
export LLMGATEWAY_API_KEY="your_api_key"Add an opencode.json in the project root:
{
"provider": {
"llmgateway": {
"options": {
"apiKey": "{env:LLMGATEWAY_API_KEY}"
}
}
},
"model": "llmgateway/claude-sonnet-5"
}llmgateway is OpenCode's provider ID. The rest of the model string is the Halfbill model ID; replace it with any model from the catalogue.
The provider already defines the Halfbill endpoint, so this configuration only supplies the key and model. For a custom endpoint override, use provider.llmgateway.options.baseURL with https://api.halfbill.uk/v1.
Verify a coding task
Ask OpenCode to fix a specific file and run its tests:
Fix slugify.ts so all tests pass. Read the files, make the smallest fix,
run node --test slugify.test.ts, and summarize. Do not edit the tests.Review the diff, approve commands as needed, and check the test output. Then confirm the request's model, tokens, and cost in your dashboard.
You can also run a one-shot task:
opencode run --model llmgateway/claude-sonnet-5 "Explain this project"Switching models
Use /models in the terminal, or list the provider's available IDs:
opencode models llmgatewayCopy an exact ID from that output into the model field or the --model option.
Troubleshooting
Provider not found
Check opencode --version and run opencode models llmgateway. Current versions use llmgateway; older instructions referring to llmgateway-providers may not match your installed release.
Authentication error
Check that the key is active and available in the shell that launches OpenCode. The environment reference uses OpenCode's {env:VARIABLE_NAME} syntax.
Model missing
Refresh the model picker or restart OpenCode. Copy the exact ID from opencode models llmgateway and compare it with the Halfbill catalogue.
See OpenCode's provider documentation for additional configuration options.
How is this guide?