I have been using the “text-davinci-003” model successfully but when I switched to “gpt-3.5-turbo” it gives me the error:
“Request failed with status code 404”
And I get the same error with “gpt-3.5-turbo-0301”.
Does it have something to do with my account? Any help would be great. thanks.
Please share the code you are using so I can tell you what is going wrong.
1 Like
Thank you. This is TypeScript.
import axios from 'axios';
interface RequestParams {
prompt: string;
model: string;
temperature: number;
}
interface ResponseData {
choices: {
text: string;
}[];
}
const apiKey = 'My Key';
const apiUrl = 'https://api.openai.com/v1/completions';
const generateNames = async (): Promise<string[]> => {
const params: RequestParams = {
prompt: 'Generate sample names for by black pet dog',
model: 'gpt-3.5-turbo-0301',
temperature: 0.6,
};
const headers = {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
};
try {
const response = await axios.post<ResponseData>(apiUrl, params, { headers });
const names = response.data.choices.map((choice) => choice.text.trim());
return names;
} catch (error) {
console.error(error);
return [];
}
};
generateNames().then((names) => {
console.log('Generated names:', names);
});
There you go.
Have you read the updated Docs? Very useful.
HTH.
No.
You must modify your API call to call the correct new chat
endpoint and properly format your chat messages, all of which is spelled out in the API docs ,
I have read these docs:
API Reference - OpenAI API
and that’s the only endpoint there. What other docs are there?
The API endpoint above is wrong for the chat
model you want to use (all in the docs)
The above is also wrong.
You are using the wrong endpoint and params for the chat
method.
You are attempting to call the model which is only for chat
by using the original completion
API code.
Example Request from Docs
curl https://api.openai.com/v1/chat/completions \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}'
I’m not trying to be too direct or too blunt, but just trying to help you save time and energy. It’s takes less than 5 minutes to read the OpenAI API docs on the chat
completion endpoint; and so reading that little bit of documentation first will save you a lot of time and effort.
For example, when the new chat
API method was released by OpenAI, I read the docs with morning coffee when I woke up, happy to see the new API method. The docs were very clear on what needed to happen and so before my coffee was lukewarm, I had a working new method to call the new chat
API.
I’m not trying to be too straight forward, I’m just explaining that after more than 40 years (nearly 50) of working in this fun IT profession, I have found that reviewing the docs saves me a lot of time and frustration.
Just some friendly advice. Hope you will not take offense.
Hope this helps.
post https://api.openai.com/v1/chat/completions the api is error gives me 404 error
look