Class: PromptBuilder::Serializers::Messages::Request
- Defined in:
- lib/prompt_builder/serializers/messages/request.rb
Overview
Request serializer for the Anthropic Messages API format.
Unsupported Open Responses features
These session fields are not supported and are silently omitted from the serialized output:
frequency_penalty— not supported by the Messages APIinclude— response-field inclusion is an Open Responses-only conceptmax_tool_calls— per-request tool-call caps are not supportedpresence_penalty— not supported by the Messages APIprompt_cache_key/prompt_cache_retention— explicit prompt cache keys are not supportedstore— server-side response storage is not supportedstream_options— stream event options are not supportedtop_logprobs— log probability output is not supportedtruncation— server-side context truncation is not supportedbackground— background/async mode is not supported on the Messages endpointtext.verbosity— Anthropic Messages has no equivalent verbosity control
Partially supported session fields (unsupported keys/values are omitted):
metadata— only theuser_idkey is forwarded;safety_identifieris also mapped intometadata.user_idautomaticallyservice_tier— onlyautoandstandard_onlyare acceptedtext—format.type=json_schemais mapped tooutput_config.formatreasoning—budget_tokens,display,effort, andtypeare forwarded;temperaturemust be unset andtop_pmust be >= 0.95 when reasoning is enabled
Input content restrictions:
InputVideocontent is not supported and is omittedRefusalContentis dropped silently (a parsed refusal can stay in session history without breaking subsequent request_payload calls)InputImagecontent is only supported in user messages (assistant images are omitted)InputImage.detailis not part of the Anthropic schema and is droppedInputImage.file_idis mapped to afilesource (Anthropic Files API beta)InputFilecontent is only supported in user messages (assistant files are omitted)InputFileis sent as adocumentblock;media_typeis forwarded when provided, otherwiseapplication/pdfis used for base64 sourcesInputFile.file_idis mapped to afilesource (Anthropic Files API beta)- Thinking blocks without a
signatureare dropped silently (cross-provider reasoning history doesn't round-trip into Anthropic) Reasoningitems withsummaryblocks have the summary dropped- Forced tool choice (+any+/+tool+ type) is incompatible with thinking enabled (raises)
CompactionandItemReferenceitems are silently skippedFunctionCallOutput.statusvaluesincomplete,failed, anderrorare mapped totool_result.is_error: true
Features in the Messages API not available through Open Responses
The following Messages API parameters cannot be set through the Open Responses canonical format:
top_k— top-K sampling parameterstop_sequences— custom stop sequencescache_control— top-level prompt-cache breakpoint selectioninference_geo— geographic inference routingmcp_servers— MCP connector beta parametercontainer— code execution container reuse parametercache_controlmarkers on system blocks, message content blocks, tool definitions, or document blocks (prompt caching)- Citations on documents and tool_result content blocks
search_resultcontent blocks- Web search, code execution, computer use, bash tool, text editor, and memory built-in tools
- Redacted thinking round-trip (+redacted_thinking+ blocks are supported when they appear in conversation history but cannot be requested via OR)
- Cryptographic thinking signatures (passed through in history but not configurable as a generation parameter)
anthropic-betaheaders and API versioning (this gem produces no HTTP request — set headers in your HTTP client)
Constant Summary collapse
- SUPPORTED_METADATA_KEYS =
["user_id"].freeze
- EFFORT_LEVELS =
["low", "medium", "high", "xhigh", "max"].freeze
- SUPPORTED_THINKING_TYPES =
["adaptive", "disabled", "enabled"].freeze
- SUPPORTED_TOOL_CHOICE_TYPES =
["any", "auto", "none", "tool"].freeze
- SUPPORTED_CITATION_TYPES =
Citation types accepted by the Messages API on text blocks. Annotations parsed from other providers (e.g. Chat Completions url_citation) have no Anthropic equivalent and are silently dropped.
[ "char_location", "content_block_location", "page_location", "search_result_location", "web_search_result_location" ].freeze