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 API -
include— response-field inclusion is an Open Responses-only concept -
max_tool_calls— per-request tool-call caps are not supported -
presence_penalty— not supported by the Messages API -
prompt_cache_key/prompt_cache_retention— explicit prompt cache keys are not supported -
store— server-side response storage is not supported -
stream_options— stream event options are not supported -
top_logprobs— log probability output is not supported -
truncation— server-side context truncation is not supported -
background— background/async mode is not supported on the Messages endpoint -
text.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_idautomatically -
service_tier— onlyautoandstandard_onlyare accepted -
text— format.type=json_schema is mapped tooutput_config.format -
reasoning—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 omitted -
RefusalContentis 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 dropped -
InputImage.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 sources -
InputFile.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/tooltype) is incompatible with thinking enabled (raises) -
CompactionandItemReferenceitems are silently skipped -
FunctionCallOutput.statusvaluesincomplete,failed, anderrorare mapped to tool_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 parameter -
stop_sequences— custom stop sequences -
cache_control— top-level prompt-cache breakpoint selection -
inference_geo— geographic inference routing -
mcp_servers— MCP connector beta parameter -
container— code execution container reuse parameter -
cache_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_thinkingblocks 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
- DEFAULT_MAX_TOKENS =
4096- 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