fix: handle OpenAI content array format in messagesToPrompt#27
Open
darrenwadley-ui wants to merge 1 commit intoatalovesyou:mainfrom
Open
fix: handle OpenAI content array format in messagesToPrompt#27darrenwadley-ui wants to merge 1 commit intoatalovesyou:mainfrom
darrenwadley-ui wants to merge 1 commit intoatalovesyou:mainfrom
Conversation
OpenAI chat completions API allows message content to be either a string
or an array of content parts [{type: "text", text: "..."}]. Clients like
OpenClaw always send content as an array, causing the proxy to pass
[object Object] to Claude CLI instead of the actual text.
Add extractContent() helper that normalizes both formats to a string.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
chrisle
added a commit
to chrisle/claude-max-api-proxy
that referenced
this pull request
Feb 27, 2026
Users can now send large prompts without E2BIG errors, use array-based content format for multimodal support, properly handle system prompts, and receive token usage data in streaming responses. Model names with any provider prefix are now correctly normalized. Changes: - Fix array content serialization preventing [object Object] bugs - Pass prompts via stdin to prevent E2BIG errors with large requests - Add proper system prompt support via --append-system-prompt flag - Include usage data in final streaming chunks - Support any provider prefix in model names (claude-max/, etc.) - Add CLAUDE_DANGEROUSLY_SKIP_PERMISSIONS env var for service mode - Update to Claude 4.5/4.6 model support Incorporates improvements from PRs atalovesyou#12, atalovesyou#13, atalovesyou#16, atalovesyou#24, atalovesyou#27 at https://github.com/atalovesyou/claude-max-api-proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
messagesToPromptto handle the case wheremsg.contentis an array of content parts instead of a plain stringextractContent()helper that normalizes both formats to a stringmsg.contentreferences inmessagesToPromptwithextractContent(msg.content)Bug
The OpenAI chat completions API allows message
contentto be either a string or an array of content part objects:{ "role": "user", "content": [{"type": "text", "text": "Hello, how are you?"}] }Clients like OpenClaw always send content in the array format. When the proxy receives this, JavaScript's template literal coerces the array to a string, producing
[object Object]instead of the actual text. This means Claude CLI receives garbage input like:instead of:
How to reproduce
Send a request to the proxy with content as an array:
Before this fix, Claude CLI would receive
[object Object]as the prompt.Fix
Added an
extractContent()helper function that:.textfields from content part arraysString(content ?? "")for any other shapeAll three uses of
msg.contentinmessagesToPrompt(system, user, assistant cases) now go through this helper.Test plan
contentas a plain string — should work as beforecontentas[{type: "text", text: "..."}]— should now correctly extract the text🤖 Generated with Claude Code