#789·flue

Cloudflare binding, chat completions: an assistant tool-call message is sent with content null, which MiniMax refuses

Author: rikbrownCreated Sep 28, 2026Updated Sep 28, 2026

Observed behaviour

With cloudflareBindingProvider and an AI Gateway, cloudflare/minimax/m3 makes a tool call. The next request, which carries the tool result, fails:

Cloudflare AI binding request failed with 400 Bad Request: {"success":false,"result":[],"messages":[],"error":[{"code":7003,"message":"Model execution failed (User Input Error): Invalid value at messages[2].content: Invalid input"}],"name":"AiGatewayError","httpCode":400,...}

The provider sends the assistant tool-call message as:

json
{"role":"assistant","content":null,"reasoning_content":"…","tool_calls":[{"id":"call_function_…","type":"function","function":{"name":"get_weather","arguments":"{\"city\":\"London\"}"}}]}

A direct env.AI.run test with the same messages: content: null fails with and without reasoning_content, and content: "" passes.

Cause and code location

In dist/cloudflare/workers-ai-provider.mjs (2.1.1), the chat-completions branch of streamCloudflareWorkersAi sends the output of pi-ai's openai-completions convertMessages unchanged. For an assistant message that holds only tool calls, that output has content: null. OpenAI accepts null there; MiniMax through the binding does not.

Proposed change

After conversion, send "" in place of null on an assistant message that has tool calls:

diff
 			const payload = {
-				messages: convertMessages(model, context, WORKERS_AI_COMPAT),
+				messages: withToolCallContent(convertMessages(model, context, WORKERS_AI_COMPAT)),
 				stream: true,
 				stream_options: { include_usage: true }
 			};
@@
+function withToolCallContent(messages) {
+	for (const message of messages) {
+		if (message.role === "assistant" && Array.isArray(message.tool_calls) && message.tool_calls.length > 0 && message.content === null) message.content = "";
+	}
+	return messages;
+}

With this change as a local patch, minimax/m3 completes a tool call and the tool-result turn through the binding. @cf/moonshotai/kimi-k2.6, @cf/moonshotai/kimi-k2.7-code, @cf/zai-org/glm-5.2, xai/grok-4.3, alibaba/qwen3.7-plus, google/gemini-2.5-flash, google/gemini-3.1-pro and google/gemini-3.5-flash-lite accept "" on the same path.