Class BedrockCodec
- All Implemented Interfaces:
ProviderCodec
This codec targets the plain Anthropic body wire format used by
Bedrock's invokeModel endpoint for Anthropic Claude models. The request and
response shapes are essentially identical to native Anthropic Messages API — the
key difference is the model identifier format and URL path.
Streaming: Bedrock's InvokeModelWithResponseStream uses the
AWS event-stream binary framing (application/vnd.amazon.eventstream). Each
streaming chunk is wrapped as a binary message with headers
(:event-type=chunk, :content-type=application/json,
:message-type=event) and a payload of
{"bytes":"<base64(chunkJson)>"}. This codec declares
StreamingFormat.AWS_EVENT_STREAM and the downstream write handler
(HttpSseResponseActionHandler) encodes each
chunk into the binary event-stream format via BedrockEventStreamEncoder.
SigV4 signing: automatic AWS SigV4 request signing for calling
real Bedrock is not yet implemented. Callers should supply auth headers
via the LlmBackend.headers() escape hatch or a signing proxy. This remains
a follow-up.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecode(HttpRequest request) encode(Completion completion, String model) encodeEmbedding(EmbeddingResponse embedding, String input) encodeStreaming(Completion completion, String model, StreamingPhysics physics) Encode a streaming completion as event-stream chunks.provider()The wire format this provider uses for streaming responses.
-
Constructor Details
-
BedrockCodec
public BedrockCodec()
-
-
Method Details
-
provider
- Specified by:
providerin interfaceProviderCodec
-
apiVersion
- Specified by:
apiVersionin interfaceProviderCodec
-
streamingFormat
Description copied from interface:ProviderCodecThe wire format this provider uses for streaming responses. Defaults toStreamingFormat.SSE; override for providers that use a different format (e.g. Ollama uses NDJSON).- Specified by:
streamingFormatin interfaceProviderCodec
-
encode
- Specified by:
encodein interfaceProviderCodec
-
encodeStreaming
public List<SseEvent> encodeStreaming(Completion completion, String model, StreamingPhysics physics) Encode a streaming completion as event-stream chunks.Delegates to
AnthropicCodec.encodeStreaming(org.mockserver.model.Completion, java.lang.String, org.mockserver.model.StreamingPhysics)to produce the Anthropic SSE events, then transforms each event'sdatapayload into a form suitable for event-stream binary wrapping. The downstream write handler performs the actual binary encoding viaBedrockEventStreamEncoder.Each event's data becomes one event-stream chunk whose payload is
{"bytes":"<base64(data)>"}.- Specified by:
encodeStreamingin interfaceProviderCodec
-
decode
- Specified by:
decodein interfaceProviderCodec
-
encodeEmbedding
- Specified by:
encodeEmbeddingin interfaceProviderCodec
-