In the last lesson, you lined up the two providers’ APIs field by field. Your draft script still imports callModel() and readReply() from model/first-call.js, a file written for one provider, with the model ID typed into the request. Switching providers would mean rewriting that file, and every new script the tea importer wants would need to know which provider it’s talking to.
In this lesson, you’ll turn that file into a small module with one function, ask(), that takes the same arguments and returns a result of the same shape whichever provider answers. You’ll keep each provider’s code in a file of its own and the model IDs in one place, so the draft script calls ask() and nothing else. Start with the model ID, the piece that changes most often.
Keep Model IDs in One Place
Right now, the model ID is a string inside callModel(), and copying that function into a new script duplicates the ID. Watch out for that pattern. Providers retire models on published dates, and after that, every request that names a retired model fails, in every file at once. Each provider announces retirements months ahead on its model deprecations page, so put that page on your watch list.
The fix is to give model IDs a home of their own. Create model/config.js with one entry per provider, and inside each, one model ID per role, the kind of model a feature asks for. This file names both providers on purpose, since it’s where every ID lives:
model/config.js
export const MODELS = {
openai: {
capable: "gpt-6.2-sol",
fast: "gpt-6.1-terra",
},
anthropic: {
capable: "claude-sonnet-5-5",
fast: "claude-haiku-5-5",
},
};
Each provider has a capable model, the one you’ve drafted replies with since your first call, and a fast model that a later script can request by name for short jobs. Both IDs for your provider sit next to the other provider’s, so the file is the one place to look when either provider retires a model.
A script never names a model again. It asks for a role, and the module looks up the ID. When the tea importer wants a newer model, you change one line in this file without changing any scripts. Make that switch on purpose.
After you connect the draft script to ask() later in this lesson, edit the model ID in config.js and run the script on a few inbox emails. Read the drafts, and keep the new ID only if they hold up. Otherwise, put the old ID back.
The button above opens the mentor with that question, if you’d like to plan how a model change would go before you need one.