Own Weights

Replacing an OpenAI API call with your own model

Replace an OpenAI API call with your own model: pick one task, test it on your own data, then serve it in your cloud. You own the resulting weights.

Updated

To replace an OpenAI API call with your own model, pick the one task that call does most often, train an open-weight model on real examples of that task, and prove on your own test set that it beats the current call. Then serve the model in your cloud account or your building, and point the code at it. Start at Own Weights for an overview of the process.

The code change is small. The real question is whether the new model is good enough, and your data answers that, not a leaderboard.

Pick one call to replace

Most AI features make several calls. One summarizes a thread, one routes a ticket, one pulls fields out of a document. Replace the call that runs most often and has a clear right answer. A narrow task gives you a narrow test, and a narrow test is easier to judge honestly.

To find that call, start with your code and your invoices. The free AI cost audit reads a repository as text on your own machine and lists each AI call, the model it uses and an estimated cost. Nothing is uploaded while it runs.

A worked example: vendor invoices

Say an accounts payable team sends each vendor invoice through one OpenAI call that returns the invoice number, vendor name, due date, currency, total and purchase order number as JSON. The payment system reads those fields without a person looking at them. That makes it a good candidate: each field is either on the page or it is not, and the right value can be checked.

Before training anything, write down the rules the team already follows. What counts as the total when a page shows a subtotal, a tax line and a deposit? Is a date like 04/05 April or May when the vendor is based abroad? What happens when the purchase order is missing? Those answers become your labels. If two people on the team would label the same invoice differently, settle the rule first. A model cannot learn a rule nobody agreed on.

Then collect a few hundred real invoices with the correct output for each one. Include the difficult ones: scans taken at an angle, multi-page invoices where the total sits on page three, and amounts written in words.

Build the test before you train

Take real inputs from your logs, with the output you would accept for each one. Keep them out of any training data. Run the current OpenAI call on them and score the results. That score is your baseline. Without it, nobody on your side can show that a replacement is better, and the switch becomes a matter of opinion.

Split the data by vendor, customer or account, never by row. If one vendor’s invoices sit in both the training and test sets, the score runs high and production disappoints, because the model has already seen that vendor’s layout. Where you can, score exact outputs, such as the right field value or the exact quoted passage. The guide to testing an LLM on your own data covers the details.

Train on one task and read the margin

Training teaches an open-weight model your task by showing it correct outputs. A model trained on one job can beat a much larger general model on that job, but only as far as your test shows. A lead smaller than the margin of error is not a lead.

We ran this idea on a public contract exam: finding and quoting the same kinds of passage across a public set of commercial contracts, scored with cross-validation so every document was judged by a model that never trained on it. Our tuned model came out ahead of general frontier models on that exam. The full results show the scores, the margins and the document groups behind them. Read that as evidence the method works on a narrow task, not as a promise for your invoices.

Common mistakes that break the switch

  • Testing on examples the model trained on. The score looks excellent, and the first week in production does not.
  • Splitting by row. The same vendor or customer on both sides inflates the result.
  • Changing the model, the prompt and the output format in one step. When something breaks, you cannot tell which change caused it.
  • Letting the old call define “correct” without checking it. The current output can contain its own mistakes. A replacement that matches them is not better.
  • Skipping the parser. A model that returns a slightly different JSON shape can pass your accuracy test and still crash the payment job. Validate every output against the schema, and count a failed parse as a failure.
  • Leaving out the rare cases. The invoices your team handles by hand once a month often matter most, so add them to the test on purpose.

Cut over in stages and keep a way back

Run the new model next to the old call on a slice of live traffic. Log both outputs and compare them against the same labeled test. Move one vendor group, one queue or a small share of invoices at a time. Keep the OpenAI call behind a flag until the new path has held up through a full month-end close, so you can switch back in one change. Pin the model version you tested, so only that version reaches production. See the guide to keeping the model you tested.

Before the switch, check these five things:

  1. The baseline score for the current call is recorded.
  2. The test set shares no vendor or account with the training data.
  3. The rare cases from the rule review are in the test.
  4. Outputs pass schema validation, and failures go to a person.
  5. The old call still works behind a flag.

Not every call should move. Open-ended chat, tasks whose right answer changes every week, and calls that run only now and then rarely repay the cost of training. If the test shows the trained model losing, keep the API call and record the result. For a closer look at one such workflow, see AI invoice processing.

If you want to know which of your calls is the best candidate, book a free audit. We map your AI spend by task from your code and invoices, and we will tell you plainly when a call should stay on the API.

Questions

Can I replace my OpenAI API calls with an open-weight model?

Yes, for a task with a clear right answer and enough real examples to teach it. Open-ended chat with no fixed output is a poor fit. Start with the single call your team would miss least.

How do I know if the replacement is good enough to switch?

Score the current call and the replacement on the same held-out inputs, with outputs your team agrees are correct. Check results by group of documents, so one good batch does not decide the question. If the replacement does not win, keep the API call.

Do I have to rewrite my application to switch?

Usually the change sits in one module: the call site, the request format and the parsing of the output. Keep the old call behind a flag during rollout so you can switch back quickly.