Skip to main content

Module chat_adapter

Module chat_adapter 

Source
Expand description

The adapter between the Anthropic Messages API, which Claude Code speaks, and OpenAI-style Chat Completions, which Amazon Ergo on Bedrock speaks (docs/specs/SPEC_BEDROCK_MODEL_ROUTE_2026_12_01.md, section 4.3). Pure: bytes in, bytes out, with no network, no async and no server state, so each rule is tested on its own.

Structs§

ChatRequest
A Chat Completions request body, and whether the caller asked for a streamed answer.
ChatRules
What a model asks of the request beyond Chat Completions itself. The default is Amazon Ergo’s (spec 4.3): it reasons before it answers, so a small output limit comes back empty and reasoning is never off.
StreamTranslator
Turns the upstream’s Chat Completions SSE into Messages SSE. Feed it the bytes as they arrive, in any chunking; what comes out does not depend on where the chunks were cut.

Enums§

RequestError
Why a Messages request cannot be sent to a text-only model.

Constants§

MAX_OUTPUT_TOKENS
The most output a request may ask for: the account’s quota is reserved up front for the whole limit.
MIN_OUTPUT_TOKENS
The least output a request may ask for: Ergo reasons before it answers, so a small limit comes back empty.

Functions§

chat_json_to_message
Turn a Chat Completions answer into one Messages body. An answer that is not JSON, or that is an error, becomes a Messages error body.
request_to_chat
Turn a Messages request body into a Chat Completions body for upstream_model. model_label is the name a person reads in the refusal when the conversation holds images.
request_to_chat_with
request_to_chat for a model with rules of its own.