OpenAI API cannot GET /completions

Hi all,

I receive an error trying to call openai API - Cannot GET /completions

Can anyone please help me to identify the problem?

const PORT = 8000;
const express = require("express");
const cors = require("cors");
const app = express();

app.use(express.json());
app.use(cors());

const API_KEY = "";

app.post("/completions", async (req, res) => {
  const options = {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "gpt-3.5-turbo",
      messages: [{ role: "user", content: req.body.message }],
      max_tokens: 100,
    }),
  };
  try {
    const response = await fetch(
      "https://api.openai.com/v1/chat/completions",
      options
    );
    const data = await response.json();
    res.send(data);
  } catch (err) {
    console.error(err);
  }
});

app.listen(PORT, () => console.log("Your server is running on PORT " + PORT));

Hi! Welcome to the forum!

It looks like you’re trying to get your own post endpoint. could that be the issue?