mlflow/mlflow · error · AIGatewayException
Cannot set both 'temperature' and 'top_p' parameters.
Error message
Cannot set both 'temperature' and 'top_p' parameters.
What it means
Anthropic's chat API rejects combining 'temperature' and 'top_p'; the MLflow gateway's Anthropic provider enforces this client-side and raises a 422 if both keys are present in the chat payload. Only one sampling knob may be set. Remove 'top_p' (keep 'temperature') to resolve.
Source
Thrown at mlflow/gateway/providers/anthropic.py:124
for value in schema.values():
match value:
case dict():
_enforce_strict_schema(value)
case list():
for item in value:
if isinstance(item, dict):
_enforce_strict_schema(item)
class AnthropicAdapter(ProviderAdapter):
@classmethod
def chat_to_model(cls, payload, config):
key_mapping = {"stop": "stop_sequences"}
payload["model"] = config.model.name
payload = rename_payload_keys(payload, key_mapping)
if "top_p" in payload and "temperature" in payload:
raise AIGatewayException(
status_code=422, detail="Cannot set both 'temperature' and 'top_p' parameters."
)
max_completion_tokens = payload.pop("max_completion_tokens", None)
max_tokens = payload.get("max_tokens") or max_completion_tokens
if max_tokens is None:
max_tokens = MLFLOW_AI_GATEWAY_ANTHROPIC_DEFAULT_MAX_TOKENS
if max_tokens > MLFLOW_AI_GATEWAY_ANTHROPIC_MAXIMUM_MAX_TOKENS:
raise AIGatewayException(
status_code=422,
detail="Invalid value for max_tokens: cannot exceed "
f"{MLFLOW_AI_GATEWAY_ANTHROPIC_MAXIMUM_MAX_TOKENS}.",
)
payload["max_tokens"] = max_tokens
if payload.pop("n", 1) != 1:
raise AIGatewayException(
status_code=422,View on GitHub (pinned to 6a27f2decc)
Solutions
- Remove 'top_p' from the payload and keep only 'temperature'.
- Alternatively remove 'temperature' and keep only 'top_p'.
- Strip one of the keys in the caller before sending if your framework always sets both.
Example fix
// before
payload = {"messages": msgs, "temperature": 0.7, "top_p": 0.9}
// after
payload = {"messages": msgs, "temperature": 0.7} Defensive patterns
Strategy: validation
Validate before calling
def sanitize_anthropic_chat(payload):
if "temperature" in payload and "top_p" in payload:
payload.pop("top_p", None)
return payload
sanitize_anthropic_chat(payload) Try / catch
try:
resp = gateway.chat(endpoint="anthropic-chat", payload=payload)
except MlflowException as e:
if "temperature" in str(e) and "top_p" in str(e):
payload.pop("top_p", None)
resp = gateway.chat(endpoint="anthropic-chat", payload=payload)
else:
raise Prevention
- Choose one sampling strategy (temperature OR top_p) at config time.
- Sanitize payloads before dispatching to Anthropic endpoints.
- Audit shared payload templates for both keys.
When it happens
Trigger: POSTing a chat request to an Anthropic gateway endpoint where both 'temperature' and 'top_p' keys exist in the payload after stop->stop_sequences renaming.
Common situations: Copying payload defaults from an OpenAI request where both were set; merging config dictionaries that each contribute one of the two keys; framework defaults that always emit both.
Related errors
- 'n' must be '1' for the Anthropic provider. Received value:
- Only function calling tool is supported, but received tool t
- Invalid value for max_tokens: cannot exceed {MLFLOW_AI_GATEW
- Cannot set both 'temperature' and 'top_p' parameters. Please
- Setting the 'stream' parameter to 'true' is not supported wi
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/8012ff8cefb701c3.
Report an issue: GitHub.