|
| 1 | +--- |
| 2 | +description: Migrate the current project's LLM integration to AnyRouter. Detect existing OpenAI / Anthropic / OpenRouter usage, swap base URL + key + model ids, preserve behavior, and add a smoke test. |
| 3 | +--- |
| 4 | + |
| 5 | +# /anyrouter:migrate |
| 6 | + |
| 7 | +You are migrating this project to **AnyRouter** — a universal OpenAI-compatible LLM gateway at `https://anyrouter.dev/api/v1`. Read the `anyrouter` skill before doing anything; it has the contract, model-id rules, and migration recipes. |
| 8 | + |
| 9 | +## Step 1 — Detect the current integration |
| 10 | + |
| 11 | +Search the repo for any of these signals and report what you find before changing anything: |
| 12 | + |
| 13 | +- Imports: `from openai import`, `import OpenAI`, `import Anthropic`, `from anthropic`, `import openrouter`. |
| 14 | +- Base URLs: `api.openai.com`, `api.anthropic.com`, `openrouter.ai/api/v1`. |
| 15 | +- Env vars: `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `OPENROUTER_API_KEY`, `ANTHROPIC_BASE_URL`, `OPENAI_BASE_URL`. |
| 16 | +- Model ids: bare `gpt-*`, bare `claude-*`, `provider/model` slugs. |
| 17 | +- SDK instances: `new OpenAI({...})`, `OpenAI(base_url=...)`, `Anthropic({...})`. |
| 18 | + |
| 19 | +Output a short table: file, line, current value, what it becomes. |
| 20 | + |
| 21 | +## Step 2 — Confirm the plan with the user |
| 22 | + |
| 23 | +Before editing, ask the user: |
| 24 | + |
| 25 | +1. Which key env var should the migrated code read — `ANYROUTER_API_KEY` (default) or an existing project name? |
| 26 | +2. Should `anthropic/*` calls keep the `/messages` endpoint (Anthropic-native) or move to `/chat/completions` (unified)? |
| 27 | +3. Pin a single model, read from env, or keep per-call overrides? |
| 28 | +4. Should `X-AnyRouter-Title / -Source / -Version` headers be added for attribution? |
| 29 | + |
| 30 | +Do not invent answers. If the user says "you decide", default to: `ANYROUTER_API_KEY`, `/chat/completions` for everything, model from `ANYROUTER_MODEL ?? "openai/gpt-5.4-mini"`, attribution headers on. |
| 31 | + |
| 32 | +## Step 3 — Edit minimally |
| 33 | + |
| 34 | +Apply the exact rules from the skill: |
| 35 | + |
| 36 | +- Base URL → `https://anyrouter.dev/api/v1` (or `https://anyrouter.dev/api` for Anthropic-native). |
| 37 | +- Key → `process.env.ANYROUTER_API_KEY` (or chosen env var). Never inline a literal. |
| 38 | +- Model ids → `provider/model`. Map common bare ids: |
| 39 | + - `gpt-4o-mini` → `openai/gpt-5.4-mini` |
| 40 | + - `gpt-4o` → `openai/gpt-5.4` |
| 41 | + - `claude-3-5-sonnet-*` → `anthropic/claude-sonnet-4.6` |
| 42 | + - `claude-3-5-haiku-*` → `anthropic/claude-haiku-4.5` |
| 43 | + - When uncertain, leave the existing id and add a TODO so the user can pick a current model from https://anyrouter.dev/models. |
| 44 | +- Reuse the existing LLM client module if one exists. Do **not** add a new one in parallel. |
| 45 | +- Keep request/response shapes, streaming behavior, and error handling identical. |
| 46 | + |
| 47 | +Touch only what you must. Don't refactor unrelated code. |
| 48 | + |
| 49 | +## Step 4 — Update `.env.example` and docs |
| 50 | + |
| 51 | +- Add `ANYROUTER_API_KEY=` to `.env.example`. |
| 52 | +- If a README mentions `OPENAI_API_KEY` / `ANTHROPIC_API_KEY` / `OPENROUTER_API_KEY`, replace those mentions with `ANYROUTER_API_KEY` and link to https://anyrouter.dev/docs/getting-started/quickstart. |
| 53 | + |
| 54 | +## Step 5 — Smoke test |
| 55 | + |
| 56 | +Add (or update) a smoke test that exercises one short prompt end-to-end. Prefer the project's existing test framework; otherwise drop a one-shot script: |
| 57 | + |
| 58 | +```bash |
| 59 | +curl https://anyrouter.dev/api/v1/chat/completions \ |
| 60 | + -H "Authorization: Bearer $ANYROUTER_API_KEY" \ |
| 61 | + -H "Content-Type: application/json" \ |
| 62 | + -d '{"model":"openai/gpt-5.4-mini","messages":[{"role":"user","content":"Reply with: anyrouter-ok"}],"max_tokens":20}' |
| 63 | +``` |
| 64 | + |
| 65 | +Run it. If it fails, do not declare the migration done — diagnose and fix. |
| 66 | + |
| 67 | +## Step 6 — Summary |
| 68 | + |
| 69 | +Report back: |
| 70 | + |
| 71 | +- Files changed (count + paths). |
| 72 | +- Bare model ids that were left as TODO for the user. |
| 73 | +- Whether streaming, tool-use, and error paths were re-verified. |
| 74 | +- The smoke test result. |
| 75 | + |
| 76 | +If anything was skipped, **say so explicitly**. Don't hide uncertainty. |
0 commit comments