Connect OpenCode to an OpenAI-compatible API
Add AELDER as an OpenCode custom API provider. Configure your API key and model, compare token prices, and check a Chat Completions connection.
https://aelder.dev/v1LOCAL CONFIGURATION
Let my agent set this up
Copy this task to an agent already running on your computer. Enter your API key locally when asked.
Help me connect OpenCode to AELDER using this guide: https://aelder.dev/docs/opencode/
Service Base URL: https://aelder.dev/v1
First inspect my installed version, active profile and configuration. Explain any mismatch with the guide before changing anything.
Use the documented local configuration or CLI method. Do not automate the GUI, install software or change permissions without asking.
Preserve existing accounts, providers, models, defaults, permissions and unrelated settings. Propose the smallest change, show a redacted diff, and back up any files before editing.
Have me enter my API key locally using the tool's secret storage or an environment variable. Never ask me to paste a key into chat, print it, or include it in a command, diff, log or commit.
Use the exact model ID I choose from my account's model list. Do not invent model IDs or assume every model supports every API format or tool feature.
Validate syntax and configuration loading before making any generation request. If there is no dry-run, say so.
Explain any proposed paid test, the model and what it sends, and ask for approval before running it. Do not send project files or private conversation history as a test.
Finish with the settings changed, checks performed and steps to restore the backup.Use AELDER as an OpenCode custom API provider with your own API key. This OpenAI-compatible setup uses the Chat Completions adapter and connects to /v1/chat/completions. Your OpenCode provider name and the model ID are separate settings.
1. Prepare your values
Copy the Base URL above, including /v1. Get an exact model ID from the authenticated models endpoint, and choose a model with tool-calling support for coding tasks.
Set SERVICE_API_KEY using your local secrets tooling, or read it in Bash or Zsh without recording the secret in shell history:
printf 'Service API key: '
IFS= read -r -s SERVICE_API_KEY
printf '\n'
export SERVICE_API_KEYStart OpenCode from this terminal so it inherits the variable. Keep the key out of source code and agent chats.
2. Merge the provider configuration
Use opencode.json in your project, or ~/.config/opencode/opencode.json for your user configuration. Preserve existing settings and merge my-api into provider rather than replacing that object.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"my-api": {
"npm": "@ai-sdk/openai-compatible",
"name": "My API",
"options": {
"baseURL": "https://aelder.dev/v1",
"apiKey": "{env:SERVICE_API_KEY}"
},
"models": {
"YOUR_MODEL_ID": {
"name": "My service model"
}
}
}
},
"model": "my-api/YOUR_MODEL_ID"
}Replace both instances of YOUR_MODEL_ID with the same exact service ID, preserving any slashes in that ID. Keep the AELDER Base URL including /v1. {env:SERVICE_API_KEY} is OpenCode’s environment interpolation syntax.
my-api/ in the top-level model is OpenCode’s provider selector. It is not an extra prefix to add to the model ID in our HTTP API. OpenCode appends /chat/completions to baseURL; do not enter the full request URL there.
The models object is an explicit local catalog. It does not automatically import every model returned by the service. Add entries for the models you want to select. If you set limit.context or limit.output, use verified limits; do not copy another model’s numbers or set invented prices.
3. Select and check
Restart OpenCode after editing the file, then run:
/modelsSelect the model under My API. The model setting provides a default; the picker changes the active selection. Start a fresh conversation for your first check. Project settings may override user settings, so confirm the provider shown in the running session.
Configuration loading and model selection do not prove that generation works. Send “Reply with OK” when ready for a billable request, and confirm the model and usage in your service dashboard.
OpenCode API costs
Choosing among versions? Compare the Claude API models and prices or the DeepSeek catalog versions and token rates, then check the selected model’s tool support before connecting.
The model you select determines the token rates. Compare model API prices before connecting, then use the cost calculator to estimate your workload. Coding sessions may send previous conversation and tool results again, so one task can involve several billable requests. Check actual usage in your AELDER dashboard.
Compatibility and connection errors
Use @ai-sdk/openai-compatible for this Chat Completions setup. OpenCode’s documented Responses route uses @ai-sdk/openai; it is a separate protocol choice and needs a model compatible with those requests.
A plain text reply does not verify tool calls, streaming recovery, reasoning controls or compaction. Test a small tool task before using a model for larger work. For 401 errors, check the environment and key. For 404 errors, check the /v1 suffix and adapter. For an unknown model, compare the registered ID with /v1/models.
If the provider is missing from /models/, check that its models object contains the selected ID and that a higher-priority configuration has not overridden it. If the terminal works but your editor session does not, check whether the process running OpenCode inherited SERVICE_API_KEY. A saved credential from another provider is not the AELDER key used in this example.
Sources: OpenCode’s custom providers and configuration. The native configuration was reviewed; live service compatibility has not been verified.
Need the key? Open your AELDER dashboard. For direct API calls, see the API reference.

