Developing
Anthropic Messages Replay Test Plan
Defines the Anthropic Messages API request and response shapes Praxis AI should cover across replay, passthrough, and translation tests.
On this page
Status: draft
Owner: franciscojavierarceo
What?
The Anthropic Messages API shapes Praxis should cover in replay, passthrough, and translation tests. Praxis validates only the envelope and the fields it owns, and native passthrough otherwise preserves request and response bodies; it does not reimplement Anthropic’s request validator.
This plan adds fixture and test coverage to the Messages API filter proposal, 00484_anthropic-messages-api-filters.md.
Sources
- Anthropic’s Messages API documentation
- Anthropic’s tool-use documentation: overview, defining tools, handling tool calls, and the tool reference
- Anthropic’s extended thinking and stop reason documentation
- A local aggregate scan of Claude Code JSONL sessions under
~/.claude/projects
The local scan was for shape discovery only. Do not copy it into fixtures unless the content has been reviewed and sanitized.
Local Session Inventory
The local Claude Code sessions are mostly client-tool traffic, which makes them a good source of realistic replay shapes:
- 114 JSONL session files and 10,300 records
- Message roles: 4,295 assistant records and 3,082 user records
- Content block types:
tool_use: 2,615tool_result: 2,615text: 1,491- string content: 434
thinking: 222image: 3
- Image source types:
base64only - Stop reasons:
tool_use: 2,948end_turn: 325stop_sequence: 17
- Common local tool names include
Bash,Read,Edit,Agent,TaskUpdate,Write,TaskCreate,Skill,WebFetch, andWebSearch. - Tool result content appears as plain strings,
is_errorstrings, lists of text blocks, and one list containing an image block.
The scan found no server tool response shapes such as server_tool_use, so
those fixtures come from public documentation or are synthetic.
Validation Policy
Praxis keeps Anthropic Messages validation narrow:
- Validate that request bodies are valid JSON objects before downstream filters depend on them.
- Classify and promote only proxy-owned routing facts such as protocol format, model, streaming mode, and whether tools are present.
- Preserve unknown request and response fields.
- Leave Anthropic-owned semantics to the backend, including model capability checks, role ordering, parameter ranges, tool schema validity, and unsupported feature combinations.
- When transforming to OpenAI Chat Completions, test only the fields Praxis actually maps or intentionally drops with an observable warning.
- When importing replay fixtures, preserve the original
source_recordsstructure. Generated replay requests and responses may be added next to the source records, but source records must not be modified to make the test pass.
Native Anthropic response paths are pure passthrough apart from Praxis-owned source, protocol, and transport metadata. Content blocks, generated JSON, tool calls, thinking blocks, usage fields, stop reasons, and provider metadata are not rewritten.
Test Matrix
Request Envelope and Classification
- Minimal Messages request with
model,max_tokens, and one user message. - String user content and array-based
textcontent. - Requests recognized by
/v1/messagespath oranthropic-versionheader even when body structure overlaps with OpenAI Chat Completions. stream: trueclassification and routing metadata.toolspresence setting the internal tools metadata.- Top-level
systemas a string and as text blocks. - Mid-conversation
systemmessages preserved when present. - Last-assistant prefill content preserved when present.
- Malformed JSON or non-object JSON rejected by the validate filter.
Content Blocks
- User and assistant
textblocks. - Image blocks with
source.typevalues:base64urlfile
- Image media types:
image/jpegimage/pngimage/gifimage/webp
thinkingandredacted_thinkingblocks in source records and responses.- Tool result nested content blocks:
textimagedocumentsearch_result
Tool Definitions
- User-defined tool with
name,description, andinput_schema. - Tool
namevalues using the documented alphanumeric, underscore, and hyphen shape. - Optional
input_examplespreserved on passthrough paths. - Optional properties preserved or intentionally handled:
cache_controlstrictdefer_loadingallowed_callers
tool_choicevariants:autoanytoolnone
- Parallel-tool controls such as
disable_parallel_tool_useand their OpenAI translation equivalent when supported. - Client-side tool names seen in local sessions, especially
Bash,Read,Edit, andWebFetch. - Anthropic-schema client tools from the public reference:
memorybashtext_editorcomputer
- Server tools from the public reference:
web_searchweb_fetchcode_executionadvisortool_searchmcp_toolset
Tool Call Lifecycle
Cover complete tool loops, not just isolated content blocks:
- Assistant message with a single
tool_useblock andstop_reason: "tool_use". - Assistant text followed by
tool_use. - Assistant message with multiple parallel
tool_useblocks. - User follow-up containing
tool_resultblocks immediately after the matching assistant tool request. tool_result.contentas:- string
- list of text blocks
- list containing an image block
- empty or omitted content
tool_result.is_error: true.- Mixed server and client tool blocks, such as
server_tool_useplus client-sidetool_use. - Pending server-tool continuations where the follow-up user message contains
only
tool_resultblocks. - Programmatic tool-calling metadata such as
callerandcontainerwhen a fixture is available.
Document ordering requirements, but enforce them only where a transformation would otherwise produce an invalid backend request.
Response and Stop Reasons
Cover each documented stop reason with a passthrough fixture or a translation unit test:
end_turnmax_tokensstop_sequencetool_usepause_turnrefusalmodel_context_window_exceeded
The refusal case should include stop_details. Tool-use responses should
include usage fields and at least one content block with type: "tool_use".
Streaming
Streaming replay waits until the replay schema can represent SSE responses.
Unit and integration tests for anthropic_messages_to_chat_completions_stream
still cover:
- Text
content_block_deltaevents. - Tool call input deltas.
- Usage deltas.
- Stop events and final message events.
- Partial UTF-8 across chunks.
- Mixed text and tool-use content in one response.
- Finish-reason mapping for tool use and max tokens.
Fixture Plan
Use sanitized local Claude Code sessions for:
- A basic text-only Messages exchange.
- A base64 image request.
- A client-tool cycle with
Bash,Read, orEdit. - A client-tool cycle with
is_error: true. - A
tool_resultwith list-based text content. - The existing list-based image tool result case.
- A response containing
thinkingfollowed by final text or tool use.
Use curated fixtures for:
- URL and file image sources.
- GIF and WebP media types if not captured locally.
- Document and search-result tool result blocks.
- Server tools and
server_tool_use. pause_turn,refusal, andmodel_context_window_exceeded.- SSE replay once the fixture schema supports it.
Each fixture needs assertions for the behavior it was added to prove. A fixture that only checks for HTTP 200 is not enough unless the shape itself is the regression target.
Priority
P0
- Add a Claude Code tool-use replay fixture that preserves source records and verifies the generated request/response remains replayable.
- Add Anthropic-to-OpenAI translation coverage for
tool_useandtool_result, including backend-visible OpenAI tool calls and tool-role messages. - Add a thinking fixture that proves source records preserve thinking content even when translation drops unsupported thinking blocks for OpenAI backends.
- Add a tool-result error fixture.
- Add a list-content tool-result fixture.
P1
- Add URL and file image source coverage.
- Add stop-reason fixtures for
max_tokens,stop_sequence, andrefusal. - Add tool-choice translation tests for
auto,any,tool, andnone. - Add optional tool-definition property passthrough tests.
P2
- Add curated server-tool fixtures.
- Add
pause_turnandmodel_context_window_exceededfixtures. - Extend replay fixtures to represent streaming SSE responses.
- Add programmatic tool-calling metadata coverage if we capture or synthesize a representative request.
Open Questions
- Should replay fixtures grow a first-class SSE response format, or should SSE stay covered only by stream parser tests for now?
- Should
anthropic_messages_requestremain envelope-only, or should Praxis validate a small set of transformation-owned invariants before converting to OpenAI Chat Completions? - How much should committed fixtures reflect Claude Code-specific tool names versus public Anthropic tool names?
- What sanitization workflow should we use for large local tool results so the original source record structure is preserved without leaking private local content?