404 Invalid URL (POST /v1/chat/completions/chat/completions/)

Hi all, I encounter [Error: 404 Invalid URL (POST /v1/chat/completions/)] and this is my code snippet:


I am creating a travel itinerary using gpt 3.5 turbo, tried other ways such as changing the baseURL to the one posted on the documentation but it did not work.

1 Like

By the way, i am using react native and expo

In your initial approach, you were attempting to use the OpenAI SDK alongside making HTTP requests.

OpenAI doesn’t offer a dedicated SDK for React Native. To integrate OpenAI’s API within your React Native and Expo projects, you should use direct HTTP requests.

  try {
    const prompt = [
      {
        role: "system",
        content: "You are a helpful assistant."
      },
      {
        role: "user",
        content: `Plan a comprehensive travel itinerary. I am travelling with family. I am going to Paris for 7 days. And I want to include the following activities: sightseeing, dining.`
      }
    ];

    const response = await fetch('https://api.openai.com/v1/chat/completions', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${OPENAI_API_KEY}`
      },
      body: JSON.stringify({
        model: "gpt-3.5-turbo",
        messages: prompt,
      }),
    });

1 Like

try removing /chat/completions/ from base url, it seems like it duplicates the path in the destination url

the method you’re using alreay includes “.chat.completions”, that probably targets the needed path already

3 Likes

how to remove / form url, as the url is not written in my code

my guess is you can enter its typescript file and edit or override with env. You can also try to override baseURL when defining openai. But if you are using the same stacks as me, this method will still give out the same error. Refer to the reply by Innovatix, where you just have to make HTTP request.