Support custom sampling parameters (temperature, top_p, top_k) for third-party models via ANTHROPIC_BASE_URL

Resolved 💬 3 comments Opened May 6, 2026 by zhemafr-netizen Closed May 9, 2026

Problem

When using Claude Code with a third-party model (e.g., Xiaomi mimo-v2.5-pro) via ANTHROPIC_BASE_URL proxy, there is no way to configure sampling parameters (temperature, top_p, top_k). Claude Code sends hardcoded defaults (likely temperature=1.0), and these parameters cannot be overridden through settings.json or environment variables.

Use Case

Many users route Claude Code through a proxy (ANTHROPIC_BASE_URL) to use non-Claude models (open-source models, custom fine-tuned models, etc.) that are exposed via an Anthropic-compatible API. These models often benefit from tuned sampling parameters — for example:

  • Lower temperature (0.3–0.7) for more deterministic code generation
  • Adjusted top_p for better reasoning quality
  • Model-specific optimal values that differ from Claude's defaults

Current Workarounds

  1. Proxy-level injection — requires controlling the proxy server and adding request-interception logic. Not feasible for all users.
  2. No workaround from Claude Code sidesettings.json schema has no temperature/top_p/top_k fields; no environment variables exist for these.

Proposed Solution

Add support for sampling parameters in settings.json, scoped to the env block or as top-level fields:

{
  "modelParameters": {
    "temperature": 0.6,
    "top_p": 0.9,
    "top_k": 40
  }
}

Or via environment variables:

ANTHROPIC_TEMPERATURE=0.6
ANTHROPIC_TOP_P=0.9
ANTHROPIC_TOP_K=40

These should be passed through to the Messages API request body. For native Claude models, the current behavior (Claude defaults) should be preserved — only apply user-specified values when explicitly set.

Why This Matters

Claude Code is increasingly used as a universal AI coding assistant that can work with any Anthropic-compatible API endpoint. Supporting sampling parameters makes it viable for teams using custom/self-hosted models alongside or instead of Claude.

Environment

  • Claude Code version: 2.1.122
  • OS: Windows 11
  • Custom model: xiaomi/mimo-v2.5-pro via ANTHROPIC_BASE_URL

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗