Your readReply() function from the last lesson returns the same three facts for both providers: the reply’s text, the stop reason, and the usage. If you opened the other provider’s half of the switches, though, you saw different names and values for those facts. The request fields and response shape differed too.
Those differences matter as soon as you leave your own provider’s code. The tea importer might move to the other provider for its prices or its models, and the examples you find online are often written for the provider you didn’t pick. In this lesson, you’ll line up the two APIs field by field, so you can translate a model call from one provider to the other. Start with the request, the half your code writes.
Line Up the Two Requests
To translate a call, you need to know where each piece of the request goes on the other side. Both versions of callModel() from the lesson Send Your First Model Call send the same four things: the model ID, the instructions, the input, and the output limit. Here’s the part of OpenAI’s version that differs—the endpoint, the headers, and the body:
const ENDPOINT = "https://api.openai.com/v1/responses";
// ...
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${settings.apiKey}`,
},
body: JSON.stringify({
model: "gpt-6.2-sol",
instructions,
input,
max_output_tokens: settings.maxOutputTokens,
}),
The same part of Anthropic’s version uses a different model ID and different names for the instructions, input, and output limit, with one extra header:
const ENDPOINT = "https://api.anthropic.com/v1/messages";
// ...
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${settings.apiKey}`,
"anthropic-version": "2026-10-21",
},
body: JSON.stringify({
model: "claude-sonnet-5-5",
system: instructions,
messages: [{ role: "user", content: input }],
max_tokens: settings.maxOutputTokens,
}),
Read the two blocks line by line, and four differences stand out:
- The endpoint and headers: OpenAI’s Responses API lives at
/v1/responsesand Anthropic’s Messages API at/v1/messages. Both take the key asAuthorization: Bearer, and Anthropic also wants ananthropic-versionheader naming the API version your code was written for. - The instructions: OpenAI calls them
instructions, and Anthropic calls themsystem. - The input: OpenAI takes the email as one string in
input. Anthropic takes a list,messages, where each message is an object with aroleand itscontent. - The output limit: OpenAI’s
max_output_tokensis optional, and Anthropic’smax_tokensis required.