#Correct Usage of API?

1 messages · Page 1 of 1 (latest)

distant dove
#

I keep getting error 404 request. Heres how I am currently using the api. Keep getting "bad request" error.

      const openAIResponse = await axios.post(
        'https://api.openai.com/v1/completions',  
        {
          model: 'text-davinci-003', // Correct model name for completions endpoint
          prompt: `Please summarize the following text into key points:\n\n${recognizedText}`,
          max_tokens: 150
        },
        {
          headers: {
            'Authorization': `Bearer ${API_KEY_OPENAI}`,
            'Content-Type': 'application/json'
          }
        }
      );

      const summary = openAIResponse.data.choices[0].text.trim();
      recognizedTexts.push(summary);
    }```
#

Using free tier

distant dove
#

esponse: {
status: 429,
statusText: 'Too Many Requests',
headers: Object [AxiosHeaders] {
date: 'Thu, 22 Aug 2024 23:41:58 GMT',
'content-type': 'application/json; charset=utf-8',
'content-length': '337',
connection: 'close',
vary: 'Origin',
'x-request-id': 'req_74502d62776f509b26591edf74e7706b',
'strict-transport-security': 'max-age=15552000; includeSubDomains; preload',
'cf-cache-status': 'DYNAMIC',
'set-cookie': [Array],
'x-content-type-options': 'nosniff',
server: 'cloudflare',
'cf-ray': '8b76b7786c5681fa-IAD',
'alt-svc': 'h3=":443"; ma=86400'
},
config: {
transitional: [Object],
adapter: [Array],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: [Object],
validateStatus: [Function: validateStatus],
headers: [Object [AxiosHeaders]],
method: 'post',
url: 'https://api.openai.com/v1/chat/completions',
data: '{"model":"gpt-3.5-turbo","messages":[{"role":"system","content":"You help summarize and find key points in notes"},{"role":"user","content":"Please summarize the following text into key points:\n\nObjects R and S each travel at a constant speed. The speed of object R is half the speed of\nobject S. Object R travels a distance of 4x inches in y seconds. Which expression represents\nthe time, in seconds, it takes object S to travel a distance of 24x inches?"}],"max_tokens":50}'
},

#

i have enough credits too

#

not sure what issue is

brisk solar
#
    statusText: 'Too Many Requests',

Check your code, maybe it loops or something and spams to OpenAI