feat: add excludeDefaultOptions for custom API compatibility #7760
+4,384
−111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add
excludeDefaultOptionsconfig for custom API compatibilityFixes #5421
Fixes #6473
Related to #2661
Problem
Custom API providers fail when OpenCode automatically injects parameters they don't support:
From #5421:
From #6473:
These errors occur because OpenCode injects default parameters that custom APIs don't support:
max_tokens/max_completion_tokenstemperature,topP,topKthinkingConfig,reasoningEffort,promptCacheKeycache_controlin messagesWhy This Solution is Better
vs PR #5541
vs #6473 Workarounds
Coverage
Solution
Add
excludeDefaultOptionsconfiguration 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)thinkingConfig,reasoningEffort,promptCacheKey,cache_control, etc.model,messages,tools,headersVerification
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