Skip to content
Try chatGet API key

OpenCode

OpenCode is an open-source coding agent for the terminal. It takes custom providers in its config file, through the AI SDK’s OpenAI-compatible package.

Copies this page's setup instructions, to paste into your coding agent.
Show the prompt
Help me set this up to use Bayle AI, an OpenAI-compatible API. Full guide: https://docs.bayle.ai/guides/coding-tools/opencode/

Goal: use Bayle models in the OpenCode terminal coding agent (https://opencode.ai).

1. Install OpenCode if `opencode --version` fails:
   npm install -g opencode-ai
   (or `brew install anomalyco/tap/opencode`; other methods: https://opencode.ai/docs)
2. Pick a model. A coding agent needs tool calls, so list the models that support them, and those tuned for code:
   curl -s "https://api.bayle.ai/models?type=text" \
     | jq -r '.data[] | select(.model_spec.capabilities.supportsFunctionCalling) | .id'
   curl -s "https://api.bayle.ai/models?type=text" \
     | jq -r '.data[] | select(.model_spec.capabilities.optimizedForCode) | .id'
   Show me both lists, let me choose, and use that id as MODEL_ID.
3. Add the provider to opencode.json, in this project or in ~/.config/opencode/opencode.json (ask me which), merging into what is there. Use @ai-sdk/openai-compatible, never @ai-sdk/openai, which calls a Responses API Bayle does not serve. The key stays a reference to the environment:
   {
     "provider": {
       "bayle": {
         "npm": "@ai-sdk/openai-compatible",
         "name": "Bayle",
         "options": {
           "baseURL": "https://api.bayle.ai",
           "apiKey": "{env:BAYLE_API_KEY}"
         },
         "models": {
           "MODEL_ID": { "name": "MODEL_ID" }
         }
       }
     }
   }
4. Verify with one real run:
   opencode run -m bayle/MODEL_ID "Reply with the word ready and change nothing."

Rules:
1. The base URL is https://api.bayle.ai exactly as written. Append no path to it.
2. Read the key from the BAYLE_API_KEY environment variable. Never write the key itself into a file you create, a command, a commit or the chat. Where the tool keeps the key in its own settings screen, tell me where to paste it. If BAYLE_API_KEY is not set, stop and ask me to create a key at https://chat.bayle.ai/developers and export it.
3. Take model ids only from GET https://api.bayle.ai/models (no key needed). Never guess one.
4. Finish with one real test request, show me the result and list the files you changed.
Terminal window
npm install -g opencode-ai

On macOS and Linux, Homebrew works too: brew install anomalyco/tap/opencode. The official docs list the other methods.

Don't have a Bayle key yet?Get API key

Set your key:

Terminal window
export BAYLE_API_KEY="your-key"

Add Bayle as a provider in opencode.json, either in your project or in ~/.config/opencode/opencode.json:

{
"provider": {
"bayle": {
"npm": "@ai-sdk/openai-compatible",
"name": "Bayle",
"options": {
"baseURL": "https://api.bayle.ai",
"apiKey": "{env:BAYLE_API_KEY}"
},
"models": {
"MODEL_ID": { "name": "MODEL_ID" }
}
}
}
}

Then pick it with /models inside OpenCode, or run one prompt directly:

Terminal window
opencode run -m bayle/MODEL_ID "Explain this repository's layout"
  • The package adds /chat/completions to baseURL.
  • Use @ai-sdk/openai-compatible, not @ai-sdk/openai. The second one calls OpenAI’s Responses API, which Bayle doesn’t serve.
  • {env:BAYLE_API_KEY} reads the key from the environment, so the file holds no secret.

A coding agent needs tool calls. List the models that support them, and those tuned for code:

Terminal window
curl -s "https://api.bayle.ai/models?type=text" \
| jq -r '.data[] | select(.model_spec.capabilities.supportsFunctionCalling) | .id'
curl -s "https://api.bayle.ai/models?type=text" \
| jq -r '.data[] | select(.model_spec.capabilities.optimizedForCode) | .id'

Add each one you want under models.