9
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ついにBedrockでOpenAIの最新モデルがGAしました!

BedrockのAPIは何種類かあり、最もよく使われるClaudeなどを呼ぶ際には Converse API を使うのですが、GPT-5.5はConverseに非対応。
代わりにOpenAI側のResponses APIをそのまま使えます。

ドキュメントはこちらです。

環境のセットアップ

# プロジェクトを作成
uv init gpt-on-bedrock

# 依存ライブラリをインストール
uv add "strands-agents[openai]" awscrt

# AWSアカウント認証を実施
aws login

シンプルにAPIを呼び出す(Responses API)

BedrockのMantleという基盤に、OpenAIのResponses API互換のエンドポイントが提供されています。

gpt_on_bedrock.py
from aws_bedrock_token_generator import provide_token
from openai import OpenAI

# OpenAI SDKをBedrock Mantle用に設定
client = OpenAI(
    base_url="https://bedrock-mantle.us-east-2.api.aws/openai/v1",
    api_key=provide_token(region="us-east-2")
)

# Responses APIで推論を実行
response = client.responses.create(
    model="openai.gpt-5.5",
    input="元気?"
)

# レスポンスのテキストを標準出力に表示
print(response.output_text)

GPT-5.5はオハイオリージョン(us-east-2)のみ対応なので注意。

以下で実行できます。

uv run gpt_on_bedrock.py

以下のHTTP 401エラーが出る場合、あなたのアカウントはGPTモデルの利用が許可されていません。

{
    "error": {
        "code": "access_denied",
        "message": "openai.gpt-5.5 is not available for this account. You can explore other available models on Amazon Bedrock. For additional access options, contact AWS Sales at https://aws.amazon.com/contact-us/sales-support/",
        "param": null,
        "type": "permission_denied_error"
    }
}
HTTP 401: Unauthorized

私の場合は、社用のEnterpriseサポート契約アカウントでは問題ありませんでしたが、個人アカウントでは許可されませんでした。残念。。

エージェントSDKから呼び出す(Strands Agents)

StrandsはResponses APIに対応しているので、これを使います。

gpt_on_strands.py
from aws_bedrock_token_generator import provide_token
from strands import Agent
from strands.models.openai_responses import OpenAIResponsesModel

# モデルを設定
model = OpenAIResponsesModel(
    model_id="openai.gpt-5.5",
    client_args={
        "base_url": "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
        "api_key": provide_token(region="us-east-2")
    }
)

# エージェントを作成
agent = Agent(model=model)

# エージェントを呼び出し
agent("元気?")

以下で実行できます。

uv run gpt_on_strands.py

おまけ

先週こんな本を出版しました。GPT-5.5を使ったエージェントを開発して、AWSでサーバーレスに動かしてみたい方はおすすめです!

9
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?