Imported from merge-api/merge-gateway-skills (
skills/migrate-direct-sdk/AGENTS.md). Install upstream withnpx skills add merge-api/merge-gateway-skills --skill migrate-direct-sdk. Copyright stays with the author.
Migrate Direct Provider SDKs to Merge Gateway
Use this instruction file when the user wants to replace direct OpenAI, Anthropic, or Google SDK calls with Merge Gateway in a Python or TypeScript project.
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:
- Python projects typically contain
pyproject.toml,requirements.txt,setup.py, or*.pyfiles. - TypeScript projects typically contain
package.json,tsconfig.json, or*.tsfiles.
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 Gateway authentication. Do not hardcode credentials.
Core Workflow
-
Search the project for direct provider SDK usage before making changes. Look for:
- OpenAI imports, constructors, and
OPENAI_API_KEY - Anthropic imports, constructors, and
ANTHROPIC_API_KEY - Google Generative AI imports, constructors,
GOOGLE_API_KEY, andGEMINI_API_KEY
- OpenAI imports, constructors, and
-
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. -
If OpenAI usage is detected, ask the user which migration path they want:
- Option A: quick migration by keeping the OpenAI SDK and pointing it at Gateway
- Option B: full migration to the native Merge Gateway SDK
-
Stop and wait for the user's answer before continuing with any OpenAI migration.
-
If the user chooses OpenAI Option A, keep the OpenAI SDK and point it at:
https://api-gateway.merge.dev/v1/openai
Replace OPENAI_API_KEY with MERGE_GATEWAY_API_KEY and prefix every model name with openai/.
-
If the user chooses OpenAI Option B, replace
OpenAIwithMergeGateway, useMERGE_GATEWAY_API_KEY, and prefix every model name withopenai/. -
If Anthropic usage is detected, replace the Anthropic SDK with
MergeGatewayby default. As an alternative only if needed, the Anthropic SDK can be kept and pointed at:
https://api-gateway.merge.dev
Do not append /v1 when keeping the Anthropic SDK. Prefix every Anthropic model name with anthropic/.
-
If Google Generative AI usage is detected, replace it with the Merge Gateway SDK. Migrate calls such as
generate_content(...),chat.send_message(...), andstart_chat()flows toclient.responses.create(...)and maintain conversation state in theinputarray. -
Map Google model names to provider-prefixed Gateway model names:
gemini-pro->google/gemini-2.0-flashgemini-pro-vision->google/gemini-2.0-flashgemini-1.5-pro->google/gemini-1.5-progemini-1.5-flash->google/gemini-1.5-flash
-
If the project uses OpenAI embeddings, migrate embeddings calls by prefixing the model name with
openai/and keep the existing response handling. -
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 provider variables rather than deleting them
- 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 - instruct them to remove the old provider secrets from that configuration
- 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.
Rules
- Always report provider search findings before making migration edits.
- Always check for partial prior migration work and preserve it.
- Always stop and wait after asking the user to choose quick migration versus full migration for OpenAI.
- 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. - Prefer updating shared model constants or config values instead of patching repeated literals one by one.
- Comment out replaced local provider environment variables instead of deleting them.
- Use the Gateway default base URL unless the user has a custom endpoint.
- When keeping the Anthropic SDK as a compatibility path, use
https://api-gateway.merge.devwithout/v1. - Explain that Google SDK migration changes API shape and requires moving to the Gateway SDK interface.
Model Mapping
Use these OpenAI model mappings when replacing bare OpenAI names:
gpt-4o->openai/gpt-4ogpt-4o-mini->openai/gpt-4o-minigpt-4-turbo->openai/gpt-4-turbogpt-3.5-turbo->openai/gpt-3.5-turboo1->openai/o1o1-mini->openai/o1-minio3-mini->openai/o3-mini
Use these Anthropic model mappings when replacing bare Anthropic names:
claude-sonnet-4-6-20250514->anthropic/claude-sonnet-4-6-20250514claude-3-5-haiku-20241022->anthropic/claude-3-5-haiku-20241022claude-3-opus-20240229->anthropic/claude-3-opus-20240229
Validation
Before finishing:
- Verify every direct provider SDK usage site was identified and either migrated or intentionally deferred.
- Verify all new model strings use
provider/modelformat. - Verify old provider environment variables are commented out locally instead of deleted.
- Verify any retained compatibility SDK uses the correct Gateway base URL.
- 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 ask the user to paste their API key into the conversation.
- Never delete old local configuration outright when it should be commented out.
- Never use bare model names without the provider prefix.
- Never keep Google's SDK API shape and claim it works unchanged through Gateway.