[PR #7760] feat: add excludeDefaultOptions for custom API compatibility #12507

Closed
opened 2026-02-16 18:17:24 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7760

State: closed
Merged: No


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_tokens
  • temperature, topP, topK
  • thinkingConfig, reasoningEffort, promptCacheKey
  • cache_control in 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

Files Changed

8 files changed: +377, -6

  • packages/opencode/src/config/config.ts - Config schema with JSDoc
  • packages/opencode/src/provider/provider.ts - Config loading with priority
  • packages/opencode/src/provider/transform.ts - Filter provider options
  • packages/opencode/src/session/llm.ts - Filter core parameters
  • packages/opencode/test/provider/provider.test.ts - 3 new tests
  • packages/opencode/test/provider/transform.test.ts - 11 new tests
  • packages/sdk/js/src/gen/types.gen.ts - SDK types
  • packages/sdk/js/src/v2/gen/types.gen.ts - SDK v2 types
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7760 **State:** closed **Merged:** No --- # 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_tokens` - `temperature`, `topP`, `topK` - `thinkingConfig`, `reasoningEffort`, `promptCacheKey` - `cache_control` in 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 ```json { "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 JSDoc - `packages/opencode/src/provider/provider.ts` - Config loading with priority - `packages/opencode/src/provider/transform.ts` - Filter provider options - `packages/opencode/src/session/llm.ts` - Filter core parameters - `packages/opencode/test/provider/provider.test.ts` - 3 new tests - `packages/opencode/test/provider/transform.test.ts` - 11 new tests - `packages/sdk/js/src/gen/types.gen.ts` - SDK types - `packages/sdk/js/src/v2/gen/types.gen.ts` - SDK v2 types
yindo added the pull-request label 2026-02-16 18:17:24 -05:00
yindo closed this issue 2026-02-16 18:17:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12507