Skip to content

Commit b735b9e

Browse files
committed
feat(llm-helper): the classic Bedrock runtime as a second surface (llm.aws.api: mantle | runtime), and the live drive's record
An account may be enabled for one Bedrock surface and not the other: the drive of 2026-10-14 found an enterprise account refusing every Claude model on the Anthropic-shaped endpoint while its classic runtime served Haiku 4.5. llm.aws.api selects mantle (the default, the SDK's AsyncAnthropicBedrockMantle with the anthropic. prefix for a bare id) or runtime (AsyncAnthropicBedrock, every model id sent as written - an inference profile id as the account lists it); llm.health names the surface; no region on either surface is the 503 by name; a bad value is a 500 by name. Two shared vectors (68) pin the runtime surface's id rule in both packs; the README, the configuration and the CHANGELOG document the two surfaces and the sign that an account lacks the default one. This pack's report gains the live drive: negative controls first, then chat, a structured verdict and a progressive stream on Haiku 4.5, and the Java engine's shipped triage graph and streaming relay in front of the helper.
1 parent 0057f20 commit b735b9e

7 files changed

Lines changed: 274 additions & 29 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
prefix and an id already spelled for Bedrock as written; server-side refusal fallbacks are never sent there (Bedrock offers
1414
none); a call whose credential chain is empty is a `503 AWS credential missing` by name. `llm.health` reports `region`
1515
beside `backend` and `model`, and its check resolves the credential chain the way a call would, without spending a token.
16-
The routes and the contract are unchanged: the shared vector file gains three Bedrock cases (66), byte-identical with the
17-
Node pack, and the Bedrock client, its region and credential checks are pinned by unit tests. **Upgrade note:** none - the
16+
Bedrock serves Claude on two surfaces and an account may be enabled for one only: `llm.aws.api` selects `mantle` (the
17+
default, the Anthropic-shaped endpoint with the prefixed ids) or `runtime` (the classic one, every model id sent as written
18+
- an inference profile id as the account lists it), and `llm.health` names the surface. Certified live on 2026-10-14 against
19+
an enterprise account, negative controls first (a wrong secret a 401 by name, no credential a 503 by name), then a chat
20+
reply, a structured verdict and a progressive stream on Haiku 4.5 through the runtime surface, from both packs and through
21+
the Java engine's shipped triage graph and streaming relay (the engines' `docs/test-reports/llm-helper-certification.md`, Scenario 8, and this pack's own report).
22+
The routes and the contract are unchanged: the shared vector file gains five Bedrock cases (68), byte-identical with the
23+
Node pack, and the Bedrock clients, their region and credential checks are pinned by unit tests. **Upgrade note:** none - the
1824
Claude API backend is the default and behaves as before; `llm.backend` now also accepts `bedrock`.
1925

2026
## Version 4.12.21, 10/7/2026

‎docs/test-reports/llm-helper-certification.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,38 @@ nothing is gathered or sent once. The long gaps are the API's own pacing, the sa
4747
no credential gave 503 through Java on all three layers and through Rust on the graph, and an invalid key gave Anthropic's 401 with its request id when this pack's client called the helper directly. The same message came from both helpers, through every layer. All traces that touched this helper rebuild
4848
as one connected tree.
4949

50+
## Verified live on AWS Bedrock (2026-10-14)
51+
52+
The helper's second backend (`llm.backend: 'bedrock'`), driven against an enterprise AWS account in `us-east-1` with temporary IAM
53+
credentials - a key pair and a session token - in the helper's environment and no vendor key anywhere. Negative controls first.
54+
55+
| Step | Result |
56+
|---|---|
57+
| A corrupted secret | `401 LLM provider error - 401 authentication_error: The request signature we calculated does not match ...` |
58+
| No credential at all | health `503 AWS credential missing`; the call a bare 500 until this pack mapped the SDK's wording (below) |
59+
| `llm.chat`, Haiku 4.5 | `200`, `ready`, 14 input / 4 output tokens |
60+
| `llm.chat` with a schema | `{"verdict": "bug", "confidence": 0.95}`, 218 / 17 |
61+
| `llm.stream` | 4 batches, the first after 815 ms, `eof` with usage 20 / 23 |
62+
| Java engine, the shipped `support-triage` graph | `bug` → `bug-filed`, 240 / 29 |
63+
| Java engine, the streaming relay | 4 `data` frames, then `done` with usage, the trace id and the correlation id |
64+
65+
Every call ran on `us.anthropic.claude-haiku-4-5-20251001-v1:0` through the classic runtime surface (`llm.aws.api: 'runtime'`): the
66+
account was enabled for that surface and not for the Anthropic-shaped one the SDK prefers, and for Haiku 4.5 and not for the newer
67+
model generation. The full account of the surfaces and the gates is Finding 7 of the
68+
[engine report](https://accenture.github.io/mercury-composable/test-reports/llm-helper-certification/).
69+
70+
## What the Python SDK needed on Bedrock
71+
72+
- **The Bedrock clients live at `anthropic.lib.bedrock`** (`AsyncAnthropicBedrockMantle`, `AsyncAnthropicBedrock`); the top level
73+
re-exports them through a star import that the type checker reads as private, so the helper imports the package path.
74+
- **An empty credential chain is a bare `RuntimeError`** raised while signing - `Could not resolve AWS credentials from session`
75+
from the Mantle client, `could not resolve credentials from session` from the classic one - so the helper matches the words both
76+
wordings carry, without case, and maps it to `503 AWS credential missing`. The health check resolves a boto3 session's
77+
credentials the way a call would, so a probe tells a missing credential from a present one without spending a token.
78+
- **No region is a construction error**, an `AnthropicError` from the Mantle client and a `ValueError` from the classic one; both
79+
are the helper's `503 AWS region missing`, raised before any call.
80+
- **The reply carries no request id:** Bedrock sends no `request-id` header the helper reads.
81+
5082
## What the Python SDK needed
5183

5284
- **No credential is not an API error.** `anthropic` 1.x raises a bare `TypeError` ("Could not resolve authentication method…")

‎examples/llm-helper/README.md‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ export AWS_REGION=us-east-1 # or llm.aws.region; the AWS credenti
3232
mercury-serve examples/llm-helper/llm_helper.py -Dllm.backend=bedrock
3333
```
3434

35+
If the account is enabled for Bedrock's classic runtime and not for its Anthropic-shaped endpoint (the default
36+
surface answers `403 ... not available for this account` on a model the console's playground runs), switch the
37+
surface and name the model as an inference profile id, exactly as the account lists it:
38+
39+
```bash
40+
mercury-serve examples/llm-helper/llm_helper.py -Dllm.backend=bedrock -Dllm.aws.api=runtime \
41+
-Dllm.model=us.anthropic.claude-haiku-4-5-20251001-v1:0
42+
```
43+
3544
The app listens on port 8086 (`rest.server.port` in `resources/application.yml`). Map its routes
3645
from the engine's `event-over-http.yaml`, as the Java and Rust MiniGraph Playgrounds do:
3746

@@ -54,7 +63,7 @@ token batches as they are produced.
5463
| `prompt` or `messages` | A single user turn, or conversation turns `[{role: user\|assistant, content}]`. `messages` wins when both are given. Content is plain text. |
5564
| `system` | Optional system prompt (text). |
5665
| `schema` | `llm.chat` only. A JSON schema; the reply is then structured output, returned parsed as `data`. `additionalProperties` defaults to `false`. A schema on `llm.stream` is a 400. |
57-
| `params.model` | The model. Default `claude-opus-5-5` (`llm.model`). On Bedrock a bare id is sent with the `anthropic.` prefix; an id already spelled for Bedrock is sent as written. |
66+
| `params.model` | The model. Default `claude-opus-5-5` (`llm.model`). On Bedrock's default surface a bare id is sent with the `anthropic.` prefix and an id already spelled for Bedrock as written; on the classic runtime surface every id is sent as written, an inference profile id as the account lists it. |
5867
| `params.max_tokens` | Output cap. Default 16000 (`llm.max.tokens`). |
5968
| `params.timeout_ms` | `llm.chat`: a deadline for the whole call, SDK retries included. `llm.stream`: the idle allowance between events. Default 60000 (`llm.timeout.ms`). |
6069
| `params.effort` | `low`, `medium`, `high`, `xhigh` or `max`. Sent only when set; otherwise the model's own default applies. A model that takes no effort parameter answers 400. |
@@ -121,6 +130,7 @@ the 422 above, not an empty stream. Raise `params.max_tokens` or lower `params.e
121130
|---|---|---|
122131
| `llm.backend` | `anthropic` | The route to the models: `anthropic` (the Claude API) or `bedrock` (AWS Bedrock); see Backends. |
123132
| `llm.aws.region` | unset | The AWS region a Bedrock call is signed for. Unset, the SDK reads `AWS_REGION` / `AWS_DEFAULT_REGION`. |
133+
| `llm.aws.api` | `mantle` | The Bedrock surface: `mantle`, the Anthropic-shaped endpoint, or `runtime`, the classic one; see Backends. |
124134
| `llm.model` | `claude-opus-5-5` | The default model. |
125135
| `llm.max.tokens` | `16000` | The default output cap. |
126136
| `llm.timeout.ms` | `60000` | The default deadline (chat) or idle allowance (stream). |
@@ -166,7 +176,7 @@ contract and the vector file are the same on every backend.
166176
| `llm.backend` | Client | Credential | Model id | Server-side fallbacks |
167177
|---|---|---|---|---|
168178
| `anthropic` (default) | the Claude API, `AsyncAnthropic` | `ANTHROPIC_API_KEY`, or whatever the SDK resolves | as written | on the models that support them |
169-
| `bedrock` | AWS Bedrock, the SDK's `AsyncAnthropicBedrockMantle` | the AWS credential chain through IAM (`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`, a profile, a role), or a Bedrock API key in `AWS_BEARER_TOKEN_BEDROCK` | a bare id gets the `anthropic.` prefix; an id already spelled for Bedrock is sent as written | none - the request never carries them |
179+
| `bedrock` | AWS Bedrock, the SDK's `AsyncAnthropicBedrockMantle` (`llm.aws.api: mantle`) or `AsyncAnthropicBedrock` (`runtime`) | the AWS credential chain through IAM (`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`, a profile, a role), or a Bedrock API key in `AWS_BEARER_TOKEN_BEDROCK` | `mantle`: a bare id gets the `anthropic.` prefix, an id already spelled for Bedrock is sent as written; `runtime`: every id as written | none - the request never carries them |
170180

171181
**AWS Bedrock.** Install the extra (`pip install 'mercury-composable[llm,bedrock]'` - it adds boto3,
172182
which signs each call), set `llm.backend: 'bedrock'` and a region (`llm.aws.region`, or `AWS_REGION`
@@ -180,6 +190,16 @@ Effort, structured output and streaming work as on the Claude API. The SDK's cli
180190
fallback middleware is not wired in; a refusal on Bedrock is the 422 or the `stop_details` of the
181191
contract, like a refusal on the Claude API with `llm.fallbacks: off`.
182192

193+
**Two surfaces.** Bedrock serves Claude on two endpoints, and an account may be enabled for one and not the
194+
other. `llm.aws.api: 'mantle'` (the default) is the Anthropic-shaped endpoint the SDK prefers, which takes the
195+
vendor-prefixed ids above. `llm.aws.api: 'runtime'` is the classic Bedrock runtime, which takes an inference profile
196+
id exactly as the account lists it (`us.anthropic.claude-haiku-4-5-20251001-v1:0` - they carry dates and versions no
197+
rule can derive, so the helper sends every id as written there). The sign that an account lacks the default surface
198+
is a `403 ... is not available for this account` on a model the console's playground runs: switch the surface and
199+
name the model as a profile id. The same message on both surfaces, with the model agreement in place, is an account
200+
enablement for that model generation - a conversation with the AWS account team, not a setting. `llm.health` reports
201+
`api` beside `backend`, `model` and `region`. Bedrock sends no `request_id` the helper reads, so a reply carries none.
202+
183203
## What it does not do
184204

185205
No tools or function calling, no images or documents, no `system` turns inside `messages`, no
@@ -189,10 +209,10 @@ deliberate: the helper is the bounded AI node of a graph, not an agent runtime.
189209
## Tests
190210

191211
`tests/test_llm_helper.py` runs the shared `tests/vectors/llm-helper-vectors.json` against a fake of
192-
the SDK (66 cases: request validation, the exact SDK call, replies, the error contract, streaming,
193-
the shape of a Bedrock call), plus the tests a vector cannot express (token batches are never held
194-
back, no prompt text in a log, the deadline cancels the call, trace annotations, health, the backend
195-
seam, the Bedrock client with its region and credential checks). No token is spent and no credential
212+
the SDK (68 cases: request validation, the exact SDK call, replies, the error contract, streaming,
213+
the shape of a Bedrock call on either surface), plus the tests a vector cannot express (token batches are
214+
never held back, no prompt text in a log, the deadline cancels the call, trace annotations, health, the
215+
backend seam, the Bedrock clients with their region and credential checks). No token is spent and no credential
196216
is needed.
197217

198218
```bash

‎examples/llm-helper/llm_helper.py‎

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
The credential comes from the environment, never from a config file: ANTHROPIC_API_KEY for
1212
the Claude API, the AWS credential chain (or AWS_BEARER_TOKEN_BEDROCK) for AWS Bedrock.
1313
Settings live in resources/application.yml (or -Dkey=value): llm.backend (anthropic or
14-
bedrock), llm.aws.region, llm.model, llm.max.tokens, llm.timeout.ms, llm.max.retries,
15-
llm.fallbacks, llm.effort. The contract, the keys and the backends are documented in
14+
bedrock), llm.aws.api (mantle or runtime), llm.aws.region, llm.model, llm.max.tokens,
15+
llm.timeout.ms, llm.max.retries, llm.fallbacks, llm.effort. The contract, the keys and the backends are documented in
1616
README.md next to this file. The Node.js twin (mercury-nodejs examples/llm-helper) speaks
1717
the same contract, and both are pinned by one shared vector file.
1818
@@ -63,13 +63,19 @@
6363
DEFAULT_PROVIDER = "anthropic"
6464
DEFAULT_BACKEND = "anthropic"
6565
BEDROCK_BACKEND = "bedrock"
66+
# the two Bedrock surfaces: the Anthropic-shaped endpoint (the default) and the classic runtime
67+
AWS_API_MANTLE = "mantle"
68+
AWS_API_RUNTIME = "runtime"
69+
AWS_APIS = (AWS_API_MANTLE, AWS_API_RUNTIME)
6670
DEFAULT_MODEL = "claude-opus-5-5"
6771
DEFAULT_MAX_TOKENS = 16000
6872
DEFAULT_TIMEOUT_MS = 60000
6973
DEFAULT_MAX_RETRIES = 2
7074
PROVIDERS = (DEFAULT_PROVIDER,)
7175
BACKENDS = (DEFAULT_BACKEND, BEDROCK_BACKEND)
72-
# Bedrock spells a model id with the vendor prefix; a bare id gets it, a prefixed one is kept
76+
# the Anthropic-shaped surface spells a model id with the vendor prefix; a bare id gets it, a
77+
# prefixed one is kept. The classic runtime takes an inference profile id exactly as the account
78+
# lists it (they carry dates and versions no rule can derive), so there the id is sent as written
7379
BEDROCK_MODEL_PREFIX = "anthropic."
7480
EFFORTS = ("low", "medium", "high", "xhigh", "max")
7581
ROLES = ("user", "assistant")
@@ -267,8 +273,9 @@ def _same_model(model: str) -> str:
267273

268274

269275
def _bedrock_model(model: str) -> str:
270-
"""A bare model id gets the prefix Bedrock expects (``anthropic.claude-opus-5-5``); an id
271-
already spelled for Bedrock - prefixed, or an inference profile - is sent as written."""
276+
"""The Anthropic-shaped surface: a bare model id gets the prefix it expects
277+
(``anthropic.claude-opus-5-5``); an id already spelled for Bedrock is sent as written. The
278+
classic runtime surface sends every id as written (``_same_model``)."""
272279
return BEDROCK_MODEL_PREFIX + model if model.startswith("claude-") else model
273280

274281

@@ -311,40 +318,54 @@ class Backend:
311318
supports_fallbacks: bool
312319
provider_model: Callable[[str], str] = _same_model
313320
credentials: Callable[[Any], str | None] = _anthropic_credentials
321+
api: str | None = None # the Bedrock surface in use, reported by llm.health
314322

315323
def credential_problem(self) -> str | None:
316324
"""What is missing for a call to be sent, or None. No token is spent."""
317325
return self.credentials(self.client)
318326

319327

320-
def backend_for(name: str, client: Any) -> Backend:
321-
"""The Backend of a route over a client: get_backend() builds the client, tests inject one."""
328+
def backend_for(name: str, client: Any, aws_api: str = AWS_API_MANTLE) -> Backend:
329+
"""The Backend of a route over a client: get_backend() builds the client, tests inject one.
330+
For Bedrock, aws_api names the surface, which decides how a model id is spelled."""
322331
if name == BEDROCK_BACKEND:
323332
return Backend(
324333
BEDROCK_BACKEND,
325334
client,
326335
supports_fallbacks=False, # server-side refusal fallbacks are not offered on Bedrock
327-
provider_model=_bedrock_model,
336+
provider_model=_bedrock_model if aws_api == AWS_API_MANTLE else _same_model,
328337
credentials=_bedrock_credentials,
338+
api=aws_api,
329339
)
330340
return Backend(DEFAULT_BACKEND, client, supports_fallbacks=True)
331341

332342

333343
_backend: Backend | None = None # built on first use - module-level so tests can inject
334344

335345

336-
def _bedrock_client() -> Any:
337-
"""AWS Bedrock through the SDK's Mantle client: the AWS credential chain (or a Bedrock API
338-
key) signs each call, and the region comes from llm.aws.region or the AWS environment."""
346+
def _aws_api() -> str:
347+
"""The Bedrock surface a call goes to: the Anthropic-shaped endpoint (mantle, the default)
348+
or the classic runtime - an account may be enabled for one and not the other."""
349+
api = str(_prop("llm.aws.api", AWS_API_MANTLE) or AWS_API_MANTLE).lower()
350+
if api not in AWS_APIS:
351+
raise AppException(500, f"llm.aws.api must be one of: {', '.join(AWS_APIS)}")
352+
return api
353+
354+
355+
def _bedrock_client(aws_api: str) -> Any:
356+
"""AWS Bedrock through the SDK's client for the chosen surface: the AWS credential chain (or
357+
a Bedrock API key) signs each call, and the region comes from llm.aws.region or the AWS
358+
environment."""
339359
if importlib.util.find_spec("boto3") is None:
340360
raise AppException(503, MISSING_BEDROCK_SDK)
341-
# the SDK reaches its Bedrock client lazily at the top level; the package path is the typed one
342-
from anthropic.lib.bedrock import AsyncAnthropicBedrockMantle
361+
# the SDK reaches its Bedrock clients lazily at the top level; the package path is the typed one
362+
from anthropic.lib.bedrock import AsyncAnthropicBedrock, AsyncAnthropicBedrockMantle
343363

364+
factory = AsyncAnthropicBedrockMantle if aws_api == AWS_API_MANTLE else AsyncAnthropicBedrock
344365
region = _prop("llm.aws.region")
345366
try:
346-
return AsyncAnthropicBedrockMantle(aws_region=str(region) if region else None)
347-
except anthropic.AnthropicError as exc: # no region, and no base URL to stand in for one
367+
return factory(aws_region=str(region) if region else None)
368+
except (anthropic.AnthropicError, ValueError) as exc: # no region, and no base URL for one
348369
raise AppException(503, MISSING_AWS_REGION) from exc
349370

350371

@@ -358,8 +379,9 @@ def get_backend() -> Backend:
358379
501, f"unknown LLM backend '{name}' - this helper serves: {', '.join(BACKENDS)}"
359380
)
360381
# credentials resolve per call, so the app starts (and reports its health) without one
361-
client = _bedrock_client() if name == BEDROCK_BACKEND else anthropic.AsyncAnthropic()
362-
backend = backend_for(name, client)
382+
aws_api = _aws_api() if name == BEDROCK_BACKEND else AWS_API_MANTLE
383+
client = _bedrock_client(aws_api) if name == BEDROCK_BACKEND else anthropic.AsyncAnthropic()
384+
backend = backend_for(name, client, aws_api)
363385
_backend = backend
364386
return backend
365387

@@ -702,6 +724,8 @@ async def llm_health(headers: dict[str, str], _body: Body) -> Any:
702724
region = getattr(backend.client, "aws_region", None)
703725
if region:
704726
info["region"] = region # which region a Bedrock call is signed for
727+
if backend.api:
728+
info["api"] = backend.api # which Bedrock surface answers
705729
return info
706730
problem = backend.credential_problem()
707731
if problem:

‎examples/llm-helper/resources/application.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ show.application.properties: 'application.name, rest.server.port, llm.backend, l
2929
llm.backend: 'anthropic'
3030
# the region a Bedrock call is signed for; unset, the SDK reads AWS_REGION / AWS_DEFAULT_REGION
3131
# llm.aws.region: 'us-east-1'
32+
# the Bedrock surface: mantle (the Anthropic-shaped endpoint, default) | runtime (the classic one,
33+
# which takes an inference profile id as the account lists it - set llm.model to that id)
34+
# llm.aws.api: 'mantle'
3235
llm.model: 'claude-opus-5-5'
3336
llm.max.tokens: 16000
3437
# llm.chat: the whole call, SDK retries included. llm.stream: the idle allowance between events.

0 commit comments

Comments
 (0)