Skip to content

fix: update chat message API to match current Claude.ai format#137

Merged
jahwag merged 2 commits into
jahwag:masterfrom
sgasser:fix/chat-message-completion-api
Dec 1, 2025
Merged

fix: update chat message API to match current Claude.ai format#137
jahwag merged 2 commits into
jahwag:masterfrom
sgasser:fix/chat-message-completion-api

Conversation

@sgasser

@sgasser sgasser commented Nov 20, 2025

Copy link
Copy Markdown
Contributor

The Claude.ai chat completion API has changed its request/response format. This fix adds the minimal required fields to make it work.

Changes:

  • Add required field to completion API request:

    • rendering_mode: "messages" (critical - without this the API times out)
  • Ensure attachments and files arrays are present (even if empty)

  • Update CLI event handler to process new SSE format:

    • Handle content_block_delta events with text_delta type
    • Extract text from delta.text field (was event.completion before)
    • Maintain backward compatibility with old format

Root cause: API was timing out because the rendering_mode field was missing. The API would accept connections but never send response events without it.

Tested: Successfully creates chats and sends/receives messages with proper streaming responses from Claude.

@sgasser sgasser requested a review from jahwag as a code owner November 20, 2025 08:48
@jahwag

jahwag commented Nov 20, 2025

Copy link
Copy Markdown
Owner

thanks for your contribution @sgasser 3 checks are failing so please see the linting error.

@jahwag jahwag left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sgasser This works well and I will approve it. First, please amend your commits to have a verified signature:
https://docs.github.com/en/enterprise-cloud@latest/authentication/managing-commit-signature-verification/about-commit-signature-verification

Thank you!

The Claude.ai chat completion API has changed its request/response format.
This fix adds the minimal required fields to make it work.

Changes:
- Add required field to completion API request:
  - rendering_mode: "messages" (critical - without this the API times out)
- Ensure attachments and files arrays are present (even if empty)

- Update CLI event handler to process new SSE format:
  - Handle content_block_delta events with text_delta type
  - Extract text from delta.text field (was event.completion before)
  - Maintain backward compatibility with old format

Root cause: API was timing out because the rendering_mode field was missing.
The API would accept connections but never send response events without it.

Tested: Successfully creates chats and sends/receives messages with proper
streaming responses from Claude.
Extract event processing logic into process_message_event helper
function to reduce complexity from 11 to 5, fixing flake8 C901 error.
@sgasser sgasser force-pushed the fix/chat-message-completion-api branch from 0b4de00 to 292b204 Compare December 1, 2025 13:51
@sgasser

sgasser commented Dec 1, 2025

Copy link
Copy Markdown
Contributor Author

All commits have been signed with GPG. The signature verification should now pass.

@jahwag jahwag merged commit 3a2cdfe into jahwag:master Dec 1, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants