





















@@ -840,7 +840,16 @@ function convertResponsesMessages(
840840msg.model !== model.id && msg.provider === model.provider && msg.api === model.api;
841841for (const block of msg.content) {
842842if (block.type === "thinking") {
843-if (shouldReplayReasoningItems && block.thinkingSignature) {
843+if (
844+shouldReplayReasoningItems &&
845+block.thinkingSignature &&
846+block.thinkingSignature.startsWith("{")
847+) {
848+// openai-completions plain-text reasoning paths persist a
849+// provenance tag (e.g. "reasoning", "reasoning_details", "content")
850+// as thinkingSignature rather than a JSON-encoded reasoning item.
851+// Replaying those values would corrupt the next request payload
852+// (OpenRouter returns HTTP 500), so skip non-JSON signatures.
844853const reasoningItem = JSON.parse(
845854block.thinkingSignature,
846855) as ReplayableResponseReasoningItem;
@@ -2878,6 +2887,14 @@ function shouldPreserveReasoningContentReplay(
28782887);
28792888}
288028892890+function shouldPreserveOpenRouterReasoningReplay(model: OpenAIModeModel): boolean {
2891+if (model.provider !== "openrouter") {
2892+return true;
2893+}
2894+const normalizedModelId = model.id.trim().toLowerCase();
2895+return !(normalizedModelId.startsWith("anthropic/") || normalizedModelId.startsWith("x-ai/"));
2896+}
2897+28812898// OpenAI Chat Completions assistant-message input does not define reasoning
28822899// replay fields, while OpenRouter and DeepSeek-style providers document
28832900// compatible pass-back contracts. Keep valid provider-owned replay fields, but
@@ -2923,7 +2940,8 @@ export function buildOpenAICompletionsParams(
29232940let messages = convertMessages(model as never, completionsContext, compat as never);
29242941injectToolCallThoughtSignatures(messages as unknown[], context, model);
29252942sanitizeCompletionsReasoningReplayFields(messages, {
2926-preserveOpenRouterReasoning: compat.thinkingFormat === "openrouter",
2943+preserveOpenRouterReasoning:
2944+compat.thinkingFormat === "openrouter" && shouldPreserveOpenRouterReasoningReplay(model),
29272945preserveReasoningContent: shouldPreserveReasoningContentReplay(model, compat),
29282946});
29292947if (compat.strictMessageKeys) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。