Migrate AWS Bedrock to Merge Gateway
Use this instruction file when the user wants to replace AWS Bedrock boto3 calls with Merge Gateway, move off Bedrock-specific request formats, or switch a Python or TypeScript project to Gateway-based model access.
Environment Setup
Before starting, update the Merge Gateway skills plugin:
claude plugin update merge-gateway@merge-gateway-skills
Wait for that command to complete before moving on.
Detect the project's language and use the matching migration examples:
- Bedrock integrations are commonly in Python through
boto3. - The replacement code can be written in Python or TypeScript with
merge-gateway-sdk. - If the project is TypeScript-based but Bedrock is accessed through a Python service layer, migrate the actual integration point rather than assuming the outer app language is the only target.
Install the Merge Gateway SDK if it is not already present:
Python:
pip3 install merge-gateway-sdk
TypeScript/Node:
npm install merge-gateway-sdk
Use MERGE_GATEWAY_API_KEY for authentication. Do not hardcode credentials.
Core Workflow
-
Search the project for Bedrock usage before making changes. Look for:
boto3.client('bedrock-runtime'),boto3.client("bedrock-runtime"), andboto3.client('bedrock')invoke_model,invoke_model_with_response_stream,converse, andconverse_stream- Bedrock model IDs such as
anthropic.claude-3-5-sonnet-20241022-v2:0,amazon.titan-text-express-v1, andmeta.llama3-1-70b-instruct-v1:0 AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, andAWS_DEFAULT_REGIONwhen they appear Bedrock-specificimport boto3andfrom botocore
-
Report all findings to the user before editing files.
-
Check for prior migration work. If
MERGE_GATEWAYconfiguration orapi-gateway.merge.devalready appears in the codebase, report what is already migrated and skip those parts. -
Install
merge-gateway-sdkif it is not already present in the project's dependencies. -
Map Bedrock model IDs to Gateway model names. Default to 1:1 mappings that preserve behavior rather than silently upgrading models.
-
Ask the user to confirm Bedrock model mappings, especially for uncommon models or models that may not have a Gateway equivalent.
-
Ask the user which migration path they want:
- Option A: quick migration by using the OpenAI SDK pointed at Gateway
- Option B: full migration to the native Merge Gateway SDK
-
Stop and wait for the user's answer before continuing.
-
If the user chooses Option A, use the OpenAI SDK pointed at:
https://api-gateway.merge.dev/v1/openai
Keep the migration focused on minimal code churn while switching credentials to MERGE_GATEWAY_API_KEY.
-
If the user chooses Option B, replace Bedrock
boto3calls withMergeGatewayand migrate toclient.responses.create(...). -
For
invoke_modelmigrations, replace provider-specific raw JSON request bodies with Gatewayinputmessages and provider-prefixedmodelnames. -
For
converseandconverse_streammigrations, convert Bedrock message objects such as{"content": [{"text": "..."}]}to Gatewayinputitems and mapinferenceConfigfields to Gateway request parameters. -
For streaming migrations, preserve streaming behavior by handling accumulated text chunks correctly and printing only the newly appended portion of each streamed response chunk.
-
Ask the user whether
boto3is used for anything besides Bedrock. -
Stop and wait for the user's answer before removing
boto3or AWS credential usage. -
If
boto3is only used for Bedrock, remove Bedrock-only dependencies and configuration. Ifboto3is used for other AWS services, remove only Bedrock-specific code. -
Ask the user whether the migration target is local development or a deployed environment.
-
Stop and wait for the user's answer before changing environment guidance.
-
For local development:
- instruct the user to add
MERGE_GATEWAY_API_KEYto.envthemselves - verify
.gitignoreincludes.env - comment out old AWS keys instead of deleting them, because they may still be needed for other AWS services
- instruct the user to add
-
For deployed or CI/CD environments:
- instruct the user to add
MERGE_GATEWAY_API_KEYto their secrets manager or CI/CD configuration - only remove
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYfrom secrets configuration if they were used solely for Bedrock
- instruct the user to add
-
Generate or update a simple verification script that sends a request through Gateway and prints both the response text and the resolved model.
Model Mapping
Use these default Bedrock-to-Gateway mappings unless the user confirms a different target:
anthropic.claude-3-5-sonnet-20241022-v2:0->anthropic/claude-3-5-sonnet-20241022anthropic.claude-3-sonnet-20240229-v1:0->anthropic/claude-3-sonnet-20240229anthropic.claude-3-haiku-20240307-v1:0->anthropic/claude-3-haiku-20240307anthropic.claude-3-opus-20240229-v1:0->anthropic/claude-3-opus-20240229meta.llama3-1-70b-instruct-v1:0->meta-llama/llama-3.1-70b-instructmeta.llama3-1-8b-instruct-v1:0->meta-llama/llama-3.1-8b-instructcohere.command-r-plus-v1:0->cohere/command-r-plus
Treat optional "latest model" upgrades as a separate follow-up, not part of the default migration.
Ask the user before changing amazon.titan-text-express-v1 or any other model without a clear Gateway equivalent.
Message Mapping
Apply these Bedrock request mappings when converting calls:
- Bedrock
{"content": [{"text": "..."}]}-> Gateway{"type": "message", "content": "..."} - Bedrock
system-> Gatewayinputitem withrole: "system" - Bedrock
inferenceConfig.maxTokens-> Gatewaymax_output_tokensor equivalent request parameter - Bedrock
inferenceConfig.temperature-> Gatewaytemperature - Bedrock
inferenceConfig.topP-> Gatewaytop_p
Rules
- Always report Bedrock search findings before making migration edits.
- Always check for partial prior migration work and preserve it.
- Always default to 1:1 model mappings unless the user explicitly approves an upgrade.
- Always stop and wait after asking the user to choose quick migration versus full migration.
- Always stop and wait after asking whether
boto3is used for anything besides Bedrock. - Always stop and wait after asking whether the target environment is local development or deployed infrastructure.
- Always use provider-prefixed model names in
provider/modelformat. - Comment out replaced local AWS credentials instead of deleting them.
- Use the Gateway default base URL unless the user has a custom endpoint.
- Preserve streaming behavior when migrating
invoke_model_with_response_streamorconverse_stream.
Validation
Before finishing:
- Verify every Bedrock usage site was identified and either migrated or intentionally deferred.
- Verify every model mapping was preserved as a 1:1 migration unless the user approved an upgrade.
- Verify all new model strings use
provider/modelformat. - Verify Bedrock request bodies and message structures were translated to Gateway request format correctly.
- Verify
boto3removal only happened if the user confirmed it was not needed for other AWS services. - Verify old local AWS keys were commented out instead of deleted.
- Verify the test script or verification path sends a request successfully through Gateway when the environment allows it.
Prohibited Actions
- Never make migration edits before reporting search findings to the user.
- Never continue past a required decision point before the user answers.
- Never silently upgrade models during migration.
- Never ask the user to paste their API key into the conversation.
- Never delete old local AWS configuration outright when it should be commented out.
- Never remove
boto3if it may still be needed for other AWS services. - Never use bare model names without the provider prefix.