12 月 2 日の朝、Platform のリリースノートで「Claude Managed Agents が Amazon Bedrock でベータになった」という一行を読みました。請求を AWS にまとめられるなら、個人開発のアプリで回しているレビュー返信の下書き処理も Bedrock へ寄せられるかもしれない——そう考えて、移植の見積もりを始めたのです。
最初、私は「Bedrock 経由」をひとつの経路だと思い込んでいました。モデル ID を書き換え、クライアントのクラスを差し替えれば終わる、と。いま思えば、入口が増えたことを告げるリリースノートを、私は読み飛ばしていたのかもしれません。ドキュメントを読み直すと、いまの Claude には Bedrock 側の入口が2つあり、どちらを通るかでリクエストの形がまるで違いました。
ツール定義を一行も触らずに済むのか、それとも送信ボディを組み替える必要があるのか。机の上で悩むより、送られる中身を直接見たほうが早いと考え、手元に模擬サーバーを立てて3経路の送信を並べました。
Bedrock 側の入口は2つあります
Anthropic のドキュメントは、Bedrock の Claude を2ページに分けて説明しています。
| 経路 | エンドポイント | 対象のモデル | Python SDK のクライアント |
|---|---|---|---|
| bedrock-mantle | bedrock-mantle.{region}.api.aws/anthropic/v1/messages | Opus 4.7 以降(Opus 5.5・Sonnet 5.5・Sonnet 5・Haiku 5.5 など) | AnthropicBedrockMantle |
| bedrock-runtime | InvokeModel / InvokeModelWithResponseStream / Converse | Opus 4.6 以前と、Fable 5.2・Mythos 5.2 | AnthropicBedrock |
mantle 側のモデル ID は anthropic.claude-sonnet-5-5 のように anthropic. が頭に付きます。Fable 5.2 と Mythos 5.2 は mantle には無く、runtime だけで提供されています。つまり、使いたいモデルが入口を決めるのです。
3経路の送信を、模擬サーバーで並べる
本物の AWS には送らず、ローカルの HTTP サーバーで SDK が送るパスとヘッダとボディを記録しました。SDK は anthropic[bedrock] 2.16.0 です。同じツール定義・同じ tool_choice で3回呼び、返り値も同じ tool_use ブロックを返すようにしています。
# capture_routes.py — 3経路の送信内容を記録する(AWS には送らない)
import json, os, threading, http.server
import anthropic
CAPTURED = []
class Recorder(http.server.BaseHTTPRequestHandler):
def do_POST(self):
size = int(self.headers.get("content-length", 0))
body = json.loads(self.rfile.read(size))
CAPTURED.append((self.path, {k.lower(): v for k, v in self.headers.items()}, body))
reply = {
"id": "msg_local", "type": "message", "role": "assistant", "model": "local",
"content": [{"type": "tool_use", "id": "toolu_1", "name": "get_weather",
"input": {"city": "Takamatsu"}}],
"stop_reason": "tool_use", "stop_sequence": None,
"usage": {"input_tokens": 10, "output_tokens": 5},
}
data = json.dumps(reply).encode()
self.send_response(200)
self.send_header("content-type", "application/json")
self.send_header("content-length", str(len(data)))
self.end_headers()
self.wfile.write(data)
def log_message(self, *args):
pass
server = http.server.HTTPServer(("127.0.0.1", 0), Recorder)
base = f"http://127.0.0.1:{server.server_port}"
threading.Thread(target=server.serve_forever, daemon=True).start()
TOOLS = [{
"name": "get_weather",
"description": "Return weather for a city",
"input_schema": {"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]},
}]
ARGS = dict(max_tokens=512, tools=TOOLS, tool_choice={"type": "auto"},
messages=[{"role": "user", "content": "高松の天気は?"}])
AWS = dict(aws_access_key="AKIATEST", aws_secret_key="dummy", aws_region="us-east-1", max_retries=0)
RUNTIME_MODEL = os.environ.get("BEDROCK_RUNTIME_MODEL_ID", "runtime-model-id")
routes = [
("direct", anthropic.Anthropic(api_key="YOUR_API_KEY", base_url=base, max_retries=0),
"claude-sonnet-5-5"),
("mantle", anthropic.AnthropicBedrockMantle(base_url=base + "/anthropic", **AWS),
"anthropic.claude-sonnet-5-5"),
("runtime", anthropic.AnthropicBedrock(base_url=base, **AWS), RUNTIME_MODEL),
]
for name, client, model in routes:
result = client.messages.create(model=model, **ARGS)
path, headers, body = CAPTURED[-1]
auth = headers.get("authorization", "-").split(" ")[0]
print(f"{name:8} {path}")
print(f" auth={auth} anthropic-version header={headers.get('anthropic-version', '-')}")
print(f" body keys={sorted(body)} tools unchanged={body['tools'] == TOOLS}")
print(f" first block={result.content[0].type}")手元の出力は次のとおりでした(runtime の行はモデル ID を伏せています)。
direct /v1/messages
auth=Bearer anthropic-version header=2026-10-21
body keys=['max_tokens', 'messages', 'model', 'tool_choice', 'tools'] tools unchanged=True
first block=tool_use
mantle /anthropic/v1/messages
auth=AWS4-HMAC-SHA256 anthropic-version header=2026-10-21
body keys=['max_tokens', 'messages', 'model', 'tool_choice', 'tools'] tools unchanged=True
first block=tool_use
runtime /model/<model-id>/invoke
auth=AWS4-HMAC-SHA256 anthropic-version header=-
body keys=['anthropic_version', 'max_tokens', 'messages', 'tool_choice', 'tools'] tools unchanged=True
first block=tool_usemantle は、直接 API とボディが完全に同じでした。違うのは署名(SigV4)とパスの頭の /anthropic だけです。一方の runtime では、model がボディから消えて URL のパスへ移り、代わりに anthropic_version がボディに入っています。anthropic-version ヘッダは送られていません。
ツール定義そのものは、3経路とも1バイトも変わりませんでした。tool_use / tool_result のやりとりも同じ形で返るので、ツールを処理する側のコードは触らずに済みます。
runtime で引っかかりやすい2つの点
ひとつ目は、anthropic_version の値です。AWS のツール使用ページの例はすべて "bedrock-2023-05-31" ですが、SDK 2.16.0 は自分の API バージョン定数(今回は 2026-10-21)を setdefault で入れていました。boto3 で手組みしたボディと SDK が送るボディは、この1か所で食い違うのです。どちらが通るかを本番で試す前に揃えたい場合は、extra_body={"anthropic_version": "bedrock-2023-05-31"} を渡せば SDK はそちらを優先し、記録上も bedrock-2023-05-31 が送られることを確かめました。
ふたつ目は、ベータ機能の渡し方です。直接 API では anthropic-beta ヘッダですが、runtime では SDK がヘッダの値をボディの anthropic_beta 配列へ写していました。
# runtime ではベータ指定がボディの配列に移る
client.beta.messages.create(
model=RUNTIME_MODEL,
betas=["context-management-2025-06-27"],
**ARGS,
)
# 記録されたボディ: {"anthropic_beta": ["context-management-2025-06-27"], "anthropic_version": ..., ...}ログ基盤で「どのベータを使ったか」をヘッダから集計している方は、runtime 経由の呼び出しだけ数字が抜けることになります。私もヘッダ側で数える作りにしていたので、移す前にボディ側も読むよう直すつもりです。
送信ボディが同じでも、使えない機能はあります
形が同じ mantle でも、機能の範囲は直接 API と同じではありません。ドキュメントが挙げている非対応を、ツール使用に関わるものだけ抜き出すと次のとおりです。
| 機能 | mantle | runtime(InvokeModel) |
|---|---|---|
| クライアント側のツール(自前ツール・Bash・Computer use など) | 使える | 使える |
| Web 検索のサーバーツール | 使えない | 使えない |
| コード実行・Web fetch のサーバーツール | 使えない | ドキュメントに記載なし |
| MCP コネクタ・プログラムからのツール呼び出し | 使えない | ドキュメントに記載なし |
| Message Batches | 使えない | SDK が送信前に例外 |
runtime の SDK は、count_tokens と Batches を呼ぶと送信せずに AnthropicError を投げました(「Token counting is not supported in Bedrock yet」)。mantle のクライアントは count_tokens をそのまま /anthropic/v1/messages/count_tokens へ送っており、通るかどうかはドキュメントに書かれていません。ここは本物の環境で一度確かめるまで、当てにしないほうが安全です。
画像や PDF を URL で渡す入力と Files API も、mantle では非対応です。送信サイズの上限が経路で違う話は、Messages API の上限が 128MB になっても、Bedrock は 20MB のままにまとめました。
移す前に、経路ごとの禁止リストで止める
送ってから 400 を見るより、送る前に「この経路では使えない」と止めたほうが原因が読みやすくなります。私はリクエストを組んだ直後に、次の関数を通すようにしました。
# route_guard.py — 経路で使えない指定を送信前に見つける
UNSUPPORTED = {
"mantle": {
"server_tool_prefixes": ("web_search_", "web_fetch_", "code_execution_", "advisor"),
"body_keys": ("mcp_servers",),
"url_sources": True,
},
"runtime": {
"server_tool_prefixes": ("web_search_",),
"body_keys": (),
"url_sources": False, # ドキュメントで確かめていないので止めない
},
}
def find_route_problems(route, body):
rule = UNSUPPORTED.get(route)
if rule is None:
return []
problems = []
for tool in body.get("tools", []):
kind = tool.get("type", "")
if kind.startswith(rule["server_tool_prefixes"]):
problems.append(f"server tool {kind} is not available on {route}")
for key in rule["body_keys"]:
if key in body:
problems.append(f"{key} is not available on {route}")
if rule["url_sources"]:
for message in body.get("messages", []):
content = message.get("content")
if not isinstance(content, list):
continue
for block in content:
source = block.get("source", {}) if isinstance(block, dict) else {}
if source.get("type") == "url":
problems.append(f"URL source in {block.get('type')} is not available on {route}")
return problems
if __name__ == "__main__":
body = {
"tools": [{"type": "web_search_20250305", "name": "web_search"},
{"name": "get_weather", "input_schema": {"type": "object"}}],
"messages": [{"role": "user", "content": [
{"type": "image", "source": {"type": "url", "url": "https://example.com/a.png"}}]}],
}
for route in ("direct", "mantle", "runtime"):
print(route, find_route_problems(route, body))実行すると、direct は空、mantle は Web 検索と URL 画像の2件、runtime は Web 検索の1件が返ります。ドキュメントで確かめられなかった項目は止めない側に倒しています。確かめていない禁止を足すと、通るはずの呼び出しまで止めてしまうからです。
確かめた差は関数に、確かめていない差は本番の一回に。 移植の見積もりでは、この線引きを崩さないようにしています。
次の一歩
いま直接 API で動いているツール使用のコードがあるなら、まずは上の記録スクリプトの TOOLS と ARGS を自分のものに差し替え、mantle の行と direct の行のボディが同じになるかを見ていただければと思います。レビュー返信の下書きのように自前ツールだけで組んだ処理なら、mantle では書き換えが要らない——というのが、今回の記録から引いた私の見立てです。SDK を 2 系へ上げる途中の方は、Python SDK を 2.0.0 に上げて動かなくなる3か所も合わせてご覧ください。