feat: Add Anthropic Messages API compatibility layer#2704
Merged
ProgrammerIn-wonderland merged 3 commits intoHeyPuter:mainfrom Mar 24, 2026
Merged
Conversation
Add a new endpoint at /puterai/anthropic/v1/messages that implements the Anthropic Messages API wire format, allowing clients using the Anthropic SDK to point directly at Puter. - New router translates between Anthropic format and Puter's internal svcAiChat.complete() pipeline - Supports non-streaming, SSE streaming (proper Anthropic event sequence), and tool use round-trips - Translates system field, tool definitions (input_schema -> parameters), and tool_result content blocks - Integration tests covering non-streaming, streaming, tool use, Anthropic SDK compatibility, and system parameter Closes HeyPuter#2554
Collaborator
|
I wrote my own test program to test this PR and seem to get this error, even though I confirmed my authtoken is correct |
Collaborator
|
Test program |
Collaborator
Collaborator
|
I modified the eggspress declaration to be and that seemed adequate |
Collaborator
|
after that, this PR seems to work fine. Good work! Tool calls, streaming, and non anthropic models seem to work as intended |
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
Adds an Anthropic Messages API compatibility endpoint at
/puterai/anthropic/v1/messages, allowing clients using the official@anthropic-ai/sdk(or any Anthropic-format HTTP client) to point directly at Puter.This mirrors the existing OpenAI compatibility layer at
/puterai/openai/v1/....Changes
New files
src/backend/src/routers/puterai/anthropic/messages.jsRouter that translates between Anthropic wire format and Puter's internalsvcAiChat.complete()pipelinetests/puterJsApiTests/ai_anthropic_messages.test.tsIntegration tests (5 test cases)Modified files
src/backend/src/services/ChatAPIService.jsOne line added to register the new routerFeatures
messageobjects withcontentblocksmessage_startcontent_block_startcontent_block_deltacontent_block_stopmessage_deltamessage_stop)input_schema) andtool_resultcontent blockssystemfieldTesting
Integration tests gated behind
do_expensive_ai_testscovering:Closes #2554