Difference between newer and older model endpoints?

Hi all I’m working with an older codebase that uses some custom code to interact with the davinci model by providing the openai key in the headers, specifying a model and calling this endpoint: https://api.openai.com/v1/completions

I want to upgrade this to “text-davinci-002” with minimal changes to the existing code so I tried omitting the model parameter and calling this endpoint instead, as seems to be recommended in the latest docs https://api.openai.com/v1/engines/text-davinci-002/completions

This seems to give an invalid_request_error “message”: "You didn’t provide an API key.

However, if I do the same thing with the new davinci endpoint https://api.openai.com/v1/engines/davinci/completions

it works great!

I am a bit confused at why that is the case, has anyone else noticed this and any suggestions?

const completionEndpoint = "https://api.openai.com/v1/engines/text-davinci-002/completions";

const openaiHeader = {
  "Content-Type": "application/json",
  Authorization: "Bearer " + OPENAI_KEY,

const generateText = ({
  max_tokens = 1000,
  stop = ["END", "***", "---", "\n"],
}: {
  prompt: string;
  max_tokens?: number;
  stop?: string[];
  model?: string;
}): typeof SSE => {
  return new SSE(completionEndpoint, {
    headers: openaiHeader,
    method: "POST",
    payload: JSON.stringify({
      prompt: prompt,
      temperature: 0.75,
      top_p: 0.95,
      max_tokens: max_tokens,
      stream: true,
      stop: stop,