Class: PromptBuilder::Serializers::Messages::Request

Inherits:
Base
  • Object
show all
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 the user_id key is forwarded; safety_identifier is also mapped into metadata.user_id automatically

  • service_tier — only auto and standard_only are accepted

  • textformat.type=json_schema is mapped to output_config.format

  • reasoningbudget_tokens, display, effort, and type are forwarded; temperature must be unset and top_p must be >= 0.95 when reasoning is enabled

Input content restrictions:

  • InputVideo content is not supported and is omitted

  • RefusalContent is dropped silently (a parsed refusal can stay in session history without breaking subsequent request_payload calls)

  • InputImage content is only supported in user messages (assistant images are omitted)

  • InputImage.detail is not part of the Anthropic schema and is dropped

  • InputImage.file_id is mapped to a file source (Anthropic Files API beta)

  • InputFile content is only supported in user messages (assistant files are omitted)

  • InputFile is sent as a document block; media_type is forwarded when provided, otherwise application/pdf is used for base64 sources

  • InputFile.file_id is mapped to a file source (Anthropic Files API beta)

  • Thinking blocks without a signature are dropped silently (cross-provider reasoning history doesn’t round-trip into Anthropic)

  • Reasoning items with summary blocks have the summary dropped

  • Forced tool choice (any/tool type) is incompatible with thinking enabled (raises)

  • Compaction and ItemReference items are silently skipped

  • FunctionCallOutput.status values incomplete, failed, and error are 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_control markers on system blocks, message content blocks, tool definitions, or document blocks (prompt caching)

  • Citations on documents and tool_result content blocks

  • search_result content 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-beta headers 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

Method Summary

Methods inherited from Base

parse_response, request_payload