/aigateway:migrate-apimfrom aigateway
Migrates AI workloads from Azure API Management to Azure AI Gateway. Inventories APIM instances, generates migration plans, and executes them one object at a time.
Ships in aigateway. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The tool does two jobs: inventory an APIM instance, and propose a migration plan. Your job is the third: work with the operator to adapt that plan, then execute it one object at a time.
Nothing separate to install: the tool ships inside this plugin. Resolve it in this order, and say which one you used:
tools/migrate-apim. In Claude Code that
root is ${CLAUDE_PLUGIN_ROOT}.tools/migrate-apim in a clone of github.com/Azure/aigateway.migrate-apim already on PATH — check with migrate-apim --version. This holds only if
someone installed it earlier; nothing publishes the command.It is a Python package with no runtime dependencies, needing 3.10 or later, so it runs from wherever it already sits:
PYTHONPATH=<tool-dir> python3 -m migrate_apim.cli --version
The examples below write migrate-apim for brevity — read that as whichever invocation you
resolved. pip install -e <path> installs the real command, but only ever from a clone: the plugin
copy lives under a path pinned to one commit, so an editable install against it breaks the next time
the plugin updates. Ask before installing anything into the operator's environment.
If none of those resolve, say so and stop. Do not approximate the tool with az commands: the
inventory's value is that it is complete and says where it is not, which a hand-rolled read is not.
Every command reads ARM with the operator's Azure CLI login, so az login has to have happened.
The tool resolves az on PATH itself, Windows included; if it is missing or logged out, that is
the first line of the error. Ask the operator to log in rather than wrapping or patching the tool.
migrate-apim collect --apim <name> -g <rg> -o inventory.json
migrate-apim plan --inventory inventory.json -o plan.json --target <gateway-resource-id>
# ... run resolve-models / discover-tools where the plan proposes them ...
# ... adapt plan.json with the operator ...
migrate-apim plan --inventory inventory.json -o plan.json # re-run; adaptations survive
--target is the gateway the plan deploys to, as a full ARM id —
/subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.ApiManagement/aigateways/<name>. It
does not have to exist yet; the first phase creates it. Without it every apply refuses, so settle
the name and resource group with the operator before planning rather than at the point of writing.
Exit codes. 0 is a clean run, including a rehearsal that wrote nothing. 1 means a blocking
preflight finding, a failed step, or an unreadable artifact; 2 is a bad invocation. Progress and
summaries go to stderr in every case — a shell that renders stderr as failure is not the tool
reporting one.
plan.json is the one living artifact. It is proposed by the tool, adapted in place, and executed.
Do not keep decisions in the conversation — the plan is the record.
Collecting an inventory and proposing a plan are read-only. Neither authorises creating anything. Do not provision a gateway because someone asked whether a migration is possible.
collect is read-only and never reads a secret. If the operator has already named a subset, honour
it; do not open by asking "the whole instance or just AI?".
Read the inventory with summary, not by hand. collect prints it at the end of its own run,
on stderr; run the command again for an inventory collected in an earlier turn, or for your own once
it has scrolled past.
migrate-apim summary inventory.json # --format markdown to paste into a report
One call gives the service and its sku, every asset with the pattern it was detected as and its
provider, model or tool counts, how many of the instance's APIs were inventoried and how many were
not and why, the secret references and which are retrievable, and the policy surface by family.
Rebuilding that with jq or python3 -c over inventory.json costs a dozen calls and hands the
operator a worse answer.
It dispatches on the artifact's kind and refuses one it does not read, so summary plan.json is
the plan's view (§2) and never an empty instance. Nor is it the coverage check: a failed read
appears under Gaps in collection, a notCollected one appears nowhere, so a summary with no
such heading is not an inventory with no gaps.
Check collection.coverage before trusting the result, for two statuses and not one. A
failed read is an unknown, not an absence. A notCollected read is also an unknown — the tool
skipped it deliberately, because APIM has no bulk read for it, and said so rather than letting
silence read as "none exist". Operation policies are off by default for that reason, and on a real
instance that is routinely over a hundred policy documents nobody has looked at.
Neither is "clean". The plan raises an item for each, and the notCollected one names the
collect flag that resolves it — re-collect and the decision rests on what those documents
actually say, rather than on not having read them.
The tool writes progress to stderr and results to stdout. Do not read stderr output as failure — some shells, PowerShell among them, present it as an error. Use the exit code. If a command does fail, report its message as written rather than working around it: it names the cause.
Every item arrives proposed, with a rationale and the options spelled out. needs-decision
means "confirm or change this", not "the tool has no opinion".
Read the items with summary, not by hand.
migrate-apim summary plan.json # counts, what is open, what is ready, prerequisites
migrate-apim summary plan.json --unsettled # every open item in full, in one call
migrate-apim summary plan.json --item telemetry # one item; any fragment naming exactly one
The detail is what you need to put an item to the operator: the question, why it is asked, what
each option costs, which one the tool proposes, whether it is blocking, the evidence behind it, and
the flags below that say it is not a question at all. Rebuilding that with jq or python3 -c
over plan.json costs a call per field and loses the flags. Then work through the unsettled items
one at a time, with whatever question tool your host exposes — names differ between hosts, so look
at the tools you have. With none, ask in prose and wait for the answer before the next one.
Group by kind, ask one dependency-ready question at a time. The plan already batches identical things — three identical rate limits are one item. Do not unbatch them.
| Kind | What you are asking |
|---|---|
reduce-surface | See the rule: what part of this API moves? See capabilities/rules.json for the publishable routes. |
translate | It maps, but the semantics differ. Which target semantics? |
accept-loss | No equivalent. Accept, compensate, retain in APIM, or block? |
enumerate | A fact that only exists at runtime or in the operator's head. |
Two enumerate items are not questions:
discover-tools, not ask. See capabilities/rules.json under the MCP runtimeOnly rule for guidance on which route to prefer, and what the result means if it falls back.capabilities/rules.json explains why; see the models rule for unresolved status.| name | What clients send as model. A default is proposed; confirm or replace. |
| scope | How gateway-wide keys and Entra RBAC replace per-product subscription keys. |
| collapse | Only the default workspace exists on the target. |
Lead with blocking: true items, and put the consequence in the question — "assistants, threads and
vector-store callers stop working" is the decision, not "44 operations are unpublishable".
To record an answer, set only status: "adapted" and decision on the item. The generator
handles the rest. Then re-run plan: adapted items are preserved, and an item is re-opened only
when the APIM facts it rested on changed, with staleReason saying what moved.
A decision is the chosen value, or an object carrying it plus the facts that option needs. Most
are the bare string. Where the option commits to something APIM cannot supply, put the value under
value and the facts beside it — the item says which in needsFact.how, and a settled item that
produces no object is the plan telling you one is still missing:
"decision": "split" // most items
"decision": {"value": "list-models", "models": ["gpt-4o", "gpt-5"]} // names the catalogue
"decision": {"value": "override", // what clients will send
"names": {"gpt-4o": "chat-fast"}} // keyed by the proposed name
"decision": {"kind": "OpenTelemetry", // where telemetry reports
"openTelemetry": {"metricsEndpoint": "https://<app-insights-otlp>/v1/metrics"}}
Write the file as UTF-8 without a BOM. plan reads one if it is there, but PowerShell's
Set-Content -Encoding utf8 writes it and older tooling will not take it back.
An item needs a human only when the target cannot do something, or when the answer exists only in a caller's head. If the answer is derivable from APIM configuration, it is a collector bug.
summary --item and --unsettled mark them: not a question for rulesGap, cannotAccept and
an item named in plannerGaps; ask it differently for evidence.targetSupports and
appliedByHand.
So: a provider you cannot identify, a dialect you cannot read, a tool list you did not fetch — these
are engineering work on migrate-apim, not questions for the operator. An item carrying rulesGap
means the mapping rules are incomplete; fix capabilities/rules.json rather than asking with the
generic options. Likewise an unrun verification is "not run", not "unknown".
An item with cannotAccept: true is an unknown — a control-plane read that failed. It cannot be
closed by accepting a loss; re-collect with the right access, or have the operator state what is
there.
The plan's plannerGaps is the same category and blocks apply. Each entry names work an item
commits to that the plan does not produce — a required field nothing supplied, or a settled
decision that yields no target object. Read it as a bug report against migrate-apim, not as a
question: re-collect if the inventory is older than the tool, otherwise fix the planner. Never
settle the named item some other way just to clear the gap; that discards the work rather than
doing it.
An item carrying evidence.targetSupports: true is a third thing again: the gateway can do this
and the installed CLI cannot author it. Say so when you put it to the operator — "the gateway
supports this, we cannot configure it from here" is a different decision from "the target cannot do
this". These come from the catalogue's serviceOnly list, and the honest outcome is usually
accept-loss plus a line in the final report telling the operator what to set by hand.
An item carrying appliedByHand is a fourth: the gateway supports it, az aigateway exposes the
command, and this tool has no builder, so apply will run no step for it. Nothing carries it
today, but the target grows faster than the tool does. Say it while the item is still being
settled, not afterwards: the decision is still worth recording, but the operator is choosing how
they will configure it. Carry the command into the final report, never report such an item as
migrated, and do not quietly run the command yourself in its place — if the operator asks you to,
that is a new agreement about writes, made with the commands in front of them.
An item carrying needsFact is settled on something the answer does not supply. compensate on a
metrics policy means "send them elsewhere" and APIM never says where, so no exporter is built and
the phase reports nothing wrong. Go back to the operator for the fact, in the shape how names.
Telemetry destination — item:telemetry/destination — is settled before applying any telemetry
phase. The planner generates it with four options and a prerequisite. See capabilities/rules.json
under the telemetry rule for the full decision guidance: what each option means, which prerequisite
it raises, and what the administrator has to do. The plan item itself carries all the logic; treat
this as passing the choice through to apply rather than re-deciding it.
Migration is additive. Everything is provisioned into the gateway; nothing is removed from APIM. A failed run leaves a partially built gateway and a source still serving as before. Retiring anything from APIM is the operator's decision after they have validated the new gateway — do not do it, and do not offer to.
Make the TODO list before the first write. apply --preflight prints the eight phases and
asks for it: create one entry per phase, in that order, with whatever task tool your host
exposes — names differ between hosts, so look at the tools you have rather than reaching for a
particular one. If you have none, say so once and print the checklist in every reply instead. A
migration runs one phase per turn over many turns; the list is what holds it together, and the
phase nobody is tracking is the phase that goes missing.
Every later apply run reprints the checklist with > on the phase being run. Tick your entries
from what the tool printed, never from memory: its list is rebuilt from the journal, yours is not.
Work one phase at a time, report what it produced, and stop for the operator before the next.
A phase listed as by hand has work this tool has no builder for and no steps to run, so
--next-phase passes over it. It is not done — carry it into the final report as configuration the
operator applies themselves.
Only once nothing is needs-decision, stale, or orphaned.
migrate-apim apply --plan plan.json --inventory inventory.json --preflight
migrate-apim apply --plan plan.json --inventory inventory.json --next-phase # rehearsal
migrate-apim apply --plan plan.json --inventory inventory.json --next-phase --execute
Start with --preflight and resolve everything blocking. Then rehearse each phase before
executing it — a run without --execute prints the exact commands, quoted so they can be pasted
and with the JSON behind each @<tempfile> printed under them, which is what you show the
operator. Read that payload: the endpoint, the resource ids and the authentication mode are only
there, and a credential in it shows as its reference id, never its value. A rehearsal writes
nothing and advances nothing, so rehearse the same phase you are about
to execute; --execute refuses a phase you have not. Phases are gateway → identity → providers → models → aliases → toolServers → policies → keys; run one per turn, report what it produced, and stop before the next.
The policies phase writes two different things. A token limit lands on each model
registration the source policy's scope covered, one model policy set per model, each keeping its
own ceiling. A rate limit or IP filter has no per-model form: the gateway holds one baseline on the
default workspace, so several source policies collapse into one and the strictest is applied — say
that when you report it, and name the variants in collapsedFrom that did not win. keys
creates nothing unless the access item was settled on gateway-key-per-consumer, and even then
no APIM key value crosses: every caller is re-keyed, which is a cutover task, not a migration step.
If a step comes back mutationUnknown, the write was accepted but its outcome could not be
established. Do not retry it. Re-running the phase reconciles it by reading the target.
If a step comes back conflict, nothing was written: an object of that name is already in the
gateway and is not the one the plan asks for, and the step names the fields that diverge. Put those
to the operator — correct the object, or settle the item and re-plan — then run the phase again.
Never work around it by creating the object yourself: where the write is a create, repeating it
either overwrites what is there or is refused for the name. Re-running a phase is always safe and
is how it converges: objects already correct are reported verified and nothing is sent for them.
Read what a phase prints, not just whether it failed. unverified means the write happened and
could not be confirmed — report it as written, never as verified. A line marked not performed
names work in that phase this tool has no implementation for: it will be absent from the gateway
until someone applies it by hand, so carry it into the final report rather than letting a phase
that printed no errors read as a phase that did everything. no steps in this phase is a real
outcome too, and worth saying out loud.
Before the first write, put the prerequisites list to the operator. These are outside the
gateway's resource provider — Foundry RBAC grants, caller AI Gateway Models User / Tools User
roles, Entra consent, mcp authorize completion, private endpoint approvals. A plan that executes
without them produces a gateway that reads as configured and does not serve traffic.
You may offer to run the ones that are commands, and you should. A prerequisite carrying a
commands array has the exact invocation the plan specified; run that, not one you compose
yourself — the role name, its definition id and the scope are all decided there. The rules:
--acknowledge
records that the work is done, so acknowledging one to get past preflight asserts something you
have not established — but recording one you just carried out and read back is what the flag is
for, and leaving it unacknowledged misreports finished work as outstanding. Say which of the two
you are doing.--acknowledge <id> records on its own; it needs no other flag, and an id the plan does not
raise is refused. The preflight note then lists what is outstanding and what is acknowledged. A
line marked CONTRADICTED is one acknowledged here that the live read says is not in place —
report the read, not the acknowledgement.apply provisioned.Some prerequisites are not commands at all — Entra consent and private endpoint approval are decisions someone makes in a portal. Do not simulate those.
Never pass a secret as a scalar CLI flag; process arguments are visible. A {"$secretRef": "..."}
placeholder is resolved from the inventory's retrieval recipe at apply time and written to a
mode-0600 file passed as @path.
The same care applies to what you read. Several Azure reads hand you a credential whether you
wanted one or not — az monitor app-insights component create and a plain ARM GET on the component
both return a connection string containing an instrumentation key. Project the field you need
(--query properties.OTLPMetricsEndpoint), not the whole resource, so the key never reaches your
transcript.
A management read-back proves saved configuration. It does not prove inference works, tools are exposed, policies are enforced, or telemetry is arriving. Keep configured and working separate, and say which you have.
So end by sending the operator to look at the gateway themselves. When no phases remain, apply
prints the link — https://ai.gateway.azure.com<resourceId>/overview — and it belongs in the final
report alongside what to check there: the models, tool servers and policies the run provisioned,
anything a phase left unverified, and anything listed as by hand. Suggest the check; their
eyes on the portal is not something you can do for them or report as done.
The migration is not finished when objects exist. Every caller changes host, path and auth header,
and for a split decision some routes moved while others stayed on APIM. The cutover guide is part
of the deliverable, not a follow-up.
Microsoft.ApiManagement/aigateways, implicit default workspace only.az aigateway. Do not substitute az rest, generic resource writes, or an SDK.--ids. Check the resolved resource type before every write.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub azure/aigateway --plugin aigateway4 skills in this plugin
/feedback-ai-gatewayCollect Azure AI Gateway session feedback on friction points and completed work. Process session summaries to extract insights: where users struggled, what was accomplished, and outcomes. Scrub sensitive identifiers and return a clean file ready for product feedback or bug reports./manage-ai-gatewayCreate, configure, administer, troubleshoot, and operate Microsoft.ApiManagement/aigateways resources with the official Azure AI Gateway CLI. Manage providers, models, aliases, MCP sources, policies, client keys, managed identities, networking, private endpoint connections, and telemetry. Use for administrator tasks, not application integration or APIM migration./use-ai-gatewayDiscover callable Azure AI Gateway model and MCP endpoints, then connect them to an existing app or developer workflow.Other plugins' skills for the same job