Migrate from OpenRouter to Merge Gateway
Use this instruction file when the user wants to switch from OpenRouter to Merge Gateway, replace OpenRouter configuration, or move OpenRouter-based SDK usage to 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 OpenRouter usage before making changes. Look for:
openrouter.aiURLs, especiallyopenrouter.ai/api/v1OPENROUTER_API_KEY,OPENROUTER_BASE_URL, andOPENROUTER_API_BASEHTTP-RefererandX-Titleheaders- config files such as
.env,.env.example,.env.local,docker-compose.yml, andconfig.yaml openaiSDK usage that is currently pointed at OpenRouter
-
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. -
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.
-
If the user chooses Option A, keep the OpenAI SDK and point it at:
https://api-gateway.merge.dev/v1/openai
Replace OPENROUTER_API_KEY with MERGE_GATEWAY_API_KEY.
-
If the user chooses Option B, replace the OpenAI client configured for OpenRouter with
MergeGatewayand useMERGE_GATEWAY_API_KEY. -
Review all model names after the client migration. OpenRouter already uses
provider/modelformat, so many model names can stay unchanged, but confirm mappings with the user for less common or provider-specific models before replacing them. -
Remove OpenRouter-specific request parameters from API calls:
transformsrouteprovidermodels
-
When migrating OpenAI-style chat calls to Gateway-native responses usage, convert message arrays to
inputitems forclient.responses.create(...). -
Remove OpenRouter-specific headers:
HTTP-RefererX-Title
-
If
default_headersor equivalent configuration contains non-OpenRouter headers, preserve those headers. -
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 OpenRouter environment 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 OpenRouter 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 OpenRouter 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.
- 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 OpenRouter environment variables instead of deleting them.
- Use the Gateway default base URL unless the user has a custom endpoint.
- Remove only OpenRouter-specific headers and parameters; preserve unrelated request configuration.
- Explain that Gateway routing and fallback behavior should be configured through Gateway policies rather than OpenRouter request parameters.
Model Guidance
Use these mappings as defaults when the project uses common OpenRouter model names:
openai/gpt-4o->openai/gpt-4oanthropic/claude-3.5-sonnet->anthropic/claude-sonnet-4-6-20250514google/gemini-pro->google/gemini-2.0-flashmeta-llama/llama-3.1-70b-instruct->meta-llama/llama-3.1-70b-instruct
Confirm uncommon model mappings with the user before changing them, because some OpenRouter models may not be available through Gateway.
Feature Mapping
Map OpenRouter features to Gateway behavior like this:
route: "fallback"-> Gateway routing policies with fallback strategiestransforms-> remove; do not carry this forwardprovider.order-> Gateway routing policy provider priorities- OpenRouter usage dashboard -> Gateway usage dashboard
- OpenRouter per-model billing -> unified billing through Gateway
Validation
Before finishing:
- Verify every OpenRouter usage site was identified and either migrated or intentionally deferred.
- Verify all retained or updated model strings use
provider/modelformat. - Verify OpenRouter-specific headers and request parameters were removed without deleting unrelated configuration.
- Verify old OpenRouter environment variables are commented out locally 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 ask the user to paste their API key into the conversation.
- Never delete old local configuration outright when it should be commented out.
- Never remove non-OpenRouter headers accidentally when cleaning up
default_headers. - Never keep OpenRouter-only parameters such as
transforms,route,provider, ormodelsand claim they still work through Gateway unchanged.