-
-
Notifications
You must be signed in to change notification settings - Fork 79.2k
[Feature]: Add supportsPromptCacheKey to Mistral transport compat patch #83709
Copy link
Copy link
Closed
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Summary
Mistral's API supports prompt caching via a
prompt_cache_keyrequest field — cached tokens are billed at 10% of the standard input price. However, OpenClaw's Mistral provider compat layer (MISTRAL_MODEL_TRANSPORT_PATCH) does not includesupportsPromptCacheKey: true, so the transport layer never injectsprompt_cache_keyinto Mistral requests, and no caching occurs.Current behaviour
MISTRAL_MODEL_TRANSPORT_PATCHinextensions/mistralcurrently contains:The transport layer in
openai-transport-streamgatesprompt_cache_keyinjection oncompat.supportsPromptCacheKey === true:Because
supportsPromptCacheKeyis absent from the Mistral patch, this branch never fires. Mistral models receive noprompt_cache_key, andusage.prompt_tokens_details.cached_tokensalways returns 0.This affects all Mistral models routed through the
api.mistral.aiendpoint:mistral-medium-latest,mistral-large-latest,mistral-small-latest, etc.Expected behaviour
When a user sets
cacheRetentionon a Mistral model (or when a non-noneretention default applies), OpenClaw should passprompt_cache_keywith the session ID on Mistral chat completion requests, matching the behaviour already implemented for other providers.Proposed fix
Add
supportsPromptCacheKey: truetoMISTRAL_MODEL_TRANSPORT_PATCH:Mistral's caching docs confirm the field is supported and the billing model: https://docs.mistral.ai/studio-api/conversations/advanced/prompt-caching
Key implementation details from their docs:
prompt_cache_keyis a top-level field on the chat completion request bodyusage.prompt_tokens_details.cached_tokensImpact
For agent workloads that resend large, stable context (system prompts, workspace files, conversation history) on every turn — which is the standard OpenClaw heartbeat pattern — the savings are significant. A 1,000-token system prompt resent across 50 turns per day at
mistral-medium-latestprices ($0.40/M) costs ~$0.02/day uncached vs ~$0.002/day cached. At scale across multiple agents this adds up.Verification
Confirmed by inspecting the installed dist on v2026.5.12:
MISTRAL_MODEL_TRANSPORT_PATCHindist/api-CgjdAt3h.js— nosupportsPromptCacheKeydist/openai-transport-stream-BWwvx0MZ.js— confirmed gated oncompat.supportsPromptCacheKey === truemistral-medium-2508as primary —cached_tokensconsistently 0 in usageHappy to test the fix if a build is available.