claude-code - 💡(How to fix) Fix Support custom sampling parameters (temperature, top_p, top_k) for third-party models via ANTHROPIC_BASE_URL [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56505Fetched 2026-05-07 03:52:40
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×3commented ×1

Root Cause

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.

Fix Action

Fix / Workaround

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.

Code Example

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

---

ANTHROPIC_TEMPERATURE=0.6
ANTHROPIC_TOP_P=0.9
ANTHROPIC_TOP_K=40
RAW_BUFFERClick to expand / collapse

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

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING