Migrating one task off a frontier API, step by step
How to migrate off LLM API calls one task at a time: audit the call, test it on your own data, train a replacement that wins, then serve it in your own cloud.
Updated
Part of: Cut your AI bill
To migrate one task off a frontier API, pick the single high-volume call that costs the most, measure the current model on your own data, then train an open-weight model that beats it on that test. Serve the replacement in your own environment and move traffic over only after it wins. The rest of your product can stay on the frontier API.
Pick one call that runs all day
Start with the call that fires most often and has a clear right answer. Extraction, classification and routing are common candidates. Open-ended chat is a weak first choice, because there is no test to pass.
Take a worked example. Suppose one step in your accounts-payable flow reads each supplier invoice and returns the vendor name, invoice number, due date, currency and total. It runs on every invoice, and a wrong total costs far more than a slow answer. That is a strong first candidate. A call that writes a weekly manager summary is not, because nobody can agree on which summary is correct.
The free AI cost audit helps you find the call. It maps AI spend by task from your code and invoices, so you can see which call is worth moving first. The script runs on your machine, makes no network calls while it reads, and uploads nothing.
Build the test before you train
Build the test from your real inputs and the answers your team accepts as correct. For the invoice call, that means a sample of invoices as they actually arrive: scanned pages that are skewed, invoices in more than one currency, totals written with a different decimal separator, and the few with no due date at all. A test built from clean, typed invoices flatters both models and tells you little about production.
Write the labelling rule for each field before anyone labels anything. “Total” might mean the amount due after tax or the subtotal before it. If two reviewers would label the same invoice differently, the test measures the reviewers, not the model. Settle the rule, then have a second person check a sample of the labels.
Score the current model on the test first. That is your baseline, and without it you cannot show the replacement is better.
Split the data by document, never by chunk. If several line items from one invoice land in both training and test, the score is inflated. Keep every piece of one document on one side of the split.
Common mistakes at this stage:
- Scoring the new model against labels nobody wrote down.
- Counting a near miss as a hit when the field feeds a payment.
- Tuning the prompt on the same documents you report the final score on.
For more on setting up this kind of test, read how to test an LLM on your own data before you switch.
Train for one job, then check it beats the current model
A frontier model handles many tasks from one prompt. A replacement only has to do one task well, so training on your labelled examples teaches it that job and nothing else.
The trained model must beat the current model on your test before it goes anywhere near production. Check the win holds for each group of documents, such as each supplier or each currency, and not only on the average. A model that wins overall but loses on one currency is not ready. If it does not win, keep the old call. A failed run still shows what the data is missing.
Compare cost per finished job, not per token
Per-token prices and cost per document answer different questions, and the second one is what your budget sees. Work out what one finished invoice costs, including every retry, the human time spent on flagged cases, and the engineering time to keep the pipeline running.
- Count retries. A call that fails a format check and runs again costs twice.
- Count review. If a reviewer corrects some outputs, price that time into the comparison.
- Check for a batch route. If results do not need to be instant, ask whether your vendor offers a discounted batch path.
- Count your own hosting in documents per hour, because a model you run is paid for in compute time.
Serve it where your data already lives
Once the replacement wins, run it in your own cloud account or on-prem. Your documents and prompts stay inside your environment, and you control the weights. For the cloud setup, see running a model in your own cloud account.
Throughput depends on how many requests are in flight at once. Load test with the concurrency your workers really use, and size for the busiest hour rather than the average.
Cut over in stages. Send a small slice of live traffic to the replacement, compare its outputs with the current model’s on the same inputs, and check the disagreements by hand. Keep the frontier call behind a switch so you can route traffic back in one step. Do not remove the old call until the numbers have held through a full business cycle, such as a month-end close.
The trade-off is that you now own a model, its serving setup and its retraining. Budget time for updates when invoice formats change.
The migration, step by step
- Audit. Map AI spend by task from your code and invoices. The audit is free.
- Evaluate. Build a test from real inputs with written labelling rules, then score the current model on it first.
- Train. Train an open-weight model on that one task. It must beat the current model on the test, in every group of documents.
- Serve. Run it in your environment, load tested at real concurrency. Move traffic over in stages.
If you want to know which of your AI calls is the best first candidate, book a free audit call. We will walk through the results with you, tell you whether a task is a good fit, and say what its test would need to look like.
Questions
How long does it take to migrate one task off a frontier API?
It depends on how many labelled examples you already have and how clear the right answer is for the task. Teams with a clean test set move faster than teams that have to build one first. The training and serving steps are usually the shorter part of the work.
Do I have to stop using the frontier API completely?
No. Keep the frontier model for every task you have not moved, and keep it as a fallback during cutover if you want one. The replacement only has to win on the one task it was trained for.
Who owns the trained model?
The customer owns the weights. The model runs in your cloud account or on-prem, so you can keep serving it after the project ends. Your documents and prompts stay inside your environment.