Skip to content

[BUG]: (Incorrect) sampling parameters are hard-coded based on model name/id #42775

Description

@sobakasu

Description

opencode automatically adds sampling parameters to chat requests for some model names/ids, even if not configured to do so.
I think that opencode should not be doing this, or there should be a way to opt-out, or it should be changed to an opt-in setting.

The defaults are defined in:

packages/opencode/src/provider/transform.ts

Specifically:

  • ProviderTransform.temperature()
  • ProviderTransform.topP()
  • ProviderTransform.topK()

They are applied in:

packages/opencode/src/session/llm/request.ts

The checks use substring matches against the model name/id (lowercased)

Current defaults include:

  • Model IDs containing north-mini-code: temperature 1.0
  • Model IDs containing qwen: temperature 0.55, top_p 1.0
  • Matching Gemini 2.5, Gemini 3 Flash/Pro, Gemini 3.1, and Gemini 3.5 Flash models: temperature 1.0, top_p 0.95, top_k 64
  • Model IDs containing glm-4.6 or glm-4.7: temperature 1.0
  • Model IDs containing minimax-m2: temperature 1.0, top_p 0.95, top_k 20 or 40
  • Model IDs containing kimi-k2: temperature 0.6 or 1.0
  • Kimi K2.5 variants: top_p 0.95
  • DeepSeek V4 Flash models: top_p 0.95 in specific cases

I discovered this when running Qwen 3.8 27B locally in llama.cpp and pointing my opencode config at it. The recommended setting for Qwen 3.8 is top-p 0.95, which is being overridden by these automatically generated sampling parameters. (I specify temperature and top-p settings in llama.cpp for the model)

This means i need to also set top_p in opencode config to work around this hardcoded value.

Plugins

none

OpenCode version

1.18.18

Steps to reproduce

  1. Configure a single local OpenAI-compatible Qwen model:

    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "llama": {
          "npm": "@ai-sdk/openai-compatible",
          "options": {
            "baseURL": "http://localhost:8001/v1"
          },
          "models": {
            "Qwen-3.8-27B": {
              "name": "Qwen-3.8-27B"
            }
          }
        }
      }
    }
  2. Select Qwen-3.8-27B.

  3. Send a prompt to the model.

  4. Inspect the request sent to the server. It contains top_p 1.0, based on the model key.

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions