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.
request_to_chatturns a Messages request into a Chat Completions request.StreamTranslatorturns the upstream SSE answer into Messages SSE events, however the bytes are chunked.chat_json_to_messagedoes the same for an answer that was not streamed.
Structs§
- Chat
Request - A Chat Completions request body, and whether the caller asked for a streamed answer.
- Chat
Rules - 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.
- Stream
Translator - 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§
- Request
Error - 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_labelis the name a person reads in the refusal when the conversation holds images. - request_
to_ chat_ with request_to_chatfor a model with rules of its own.