opencode
opencode copied to clipboard
feat: add excludeDefaultOptions for custom API compatibility
Add excludeDefaultOptions config for custom API compatibility
Fixes #5421
Fixes #6473
Related to #2661
Problem
Custom API providers fail when OpenCode automatically injects parameters they don't support:
From #5421:
Unsupported parameter: 'max_tokens' is not supported with this model.
Use 'max_completion_tokens' instead.
From #6473:
litellm.BadRequestError: invalid beta flag
These errors occur because OpenCode injects default parameters that custom APIs don't support:
max_tokens/max_completion_tokenstemperature,topP,topKthinkingConfig,reasoningEffort,promptCacheKeycache_controlin messages
Why This Solution is Better
vs PR #5541
- #5541: Only fixes Azure reasoning models (hardcoded logic)
- This PR: Works for ANY custom API (config-driven)
vs #6473 Workarounds
- Workarounds: Require plugins or LiteLLM hacks
- This PR: Built-in config option, no external dependencies
Coverage
- ✅ Solves 3 related issues at once (#5421, #6473, #2661)
- ✅ 14 new unit tests
- ✅ JSDoc documentation
- ✅ Fully backward compatible
Solution
Add excludeDefaultOptions configuration at provider and model levels to disable all default parameter injection.
Config priority: model > provider > default (false)
Usage
{
"provider": {
"custom-api": {
"excludeDefaultOptions": true,
"npm": "@ai-sdk/openai-compatible",
"options": { "baseURL": "...", "apiKey": "..." },
"models": {
"model-1": { "name": "Model 1" },
"model-2": { "excludeDefaultOptions": false }
}
}
}
}
What Gets Filtered
When excludeDefaultOptions: true:
- ❌
temperature,topP,topK,maxOutputTokens(unless explicitly in agent config) - ❌ Provider options:
thinkingConfig,reasoningEffort,promptCacheKey,cache_control, etc. - ✅ Core parameters always sent:
model,messages,tools,headers
Verification
- ✅ 144 tests pass (14 new tests added)
- ✅ Tested with custom API proxy - no more unsupported parameter errors
- ✅ Tested scenarios from #5421 and #6473
- ✅ Default behavior unchanged when not configured
Files Changed
8 files changed: +377, -6
packages/opencode/src/config/config.ts- Config schema with JSDocpackages/opencode/src/provider/provider.ts- Config loading with prioritypackages/opencode/src/provider/transform.ts- Filter provider optionspackages/opencode/src/session/llm.ts- Filter core parameterspackages/opencode/test/provider/provider.test.ts- 3 new testspackages/opencode/test/provider/transform.test.ts- 11 new testspackages/sdk/js/src/gen/types.gen.ts- SDK typespackages/sdk/js/src/v2/gen/types.gen.ts- SDK v2 types