429:Too many requests while im in devlopment mode useing gpt3.5 but sent only 5requests today

the problem is gone now .
i dont know how it got here ,i dont know when it left .
all i can think of is that there is something going on with the chat api server .and ,that s not my concern.

i did not send to many requests ,i sent no more then 5 requests but got blocked instantly,
my payment is on another account ,and its not out of money!
could some one help us ? it was all fine last frieday!

err Error: Request failed with status code 429
    at createError (D:\webstorm_projects\koa-gpt\node_modules\openai\node_modules\axios\lib\core\createError.js:16:15)
    at settle (D:\webstorm_projects\koa-gpt\node_modules\openai\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (D:\webstorm_projects\koa-gpt\node_modules\openai\node_modules\axios\lib\adapters\http.js:322:11)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1358:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  config: {
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    },
    adapter: [Function: httpAdapter],
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: Infinity,
    validateStatus: [Function: validateStatus],
    headers: {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/json',
      'User-Agent': 'OpenAI/NodeJS/3.2.1',
      Authorization: 'Bearer ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■n52K9ENB',
      'Content-Length': 391,
      host: 'api.openai.com'
    },
    method: 'post',
    proxy: { host: '127.0.0.1', port: 7890, protocol: 'socks5' },
    data: '{"model":"gpt-3.5-turbo","messages":[{"role":"assistant","content":"嘿,早上好啊,chat"},{"role":"assistant","content":"你知道一首歌的歌词么?歌词如下:Fire.Fire draugen fire"},{"role":"assistant","content":"我们继续聊"},{"role":"assistant","content":"我们继续聊天"},{"role":"assistant","content":"2356"}],"max_tokens":2048,"temperature":0.9,"stream":true}',
    url: 'https://api.openai.com/v1/chat/completions'
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      socket: [Function (anonymous)],
      timeout: [Function (anonymous)],
      finish: [Function: requestOnFinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: false,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    maxRequestsOnConnectionReached: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: true,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    strictContentLength: false,
    _contentLength: 391,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: false,
    socket: Socket {
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: null,
      _closeAfterHandlingError: false,
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: null,
      _server: null,
      parser: null,
      _httpMessage: [Circular *1],
      [Symbol(async_id_symbol)]: 418,
      [Symbol(kHandle)]: [TCP],
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(kSetKeepAlive)]: true,
      [Symbol(kSetKeepAliveInitialDelay)]: 60,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(RequestTimeout)]: undefined
    },
    _header: 'POST https://api.openai.com/v1/chat/completions HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'Content-Type: application/json\r\n' +
      'User-Agent: OpenAI/NodeJS/3.2.1\r\n' +
      'Authorization: Bearer ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■n52K9ENB\r\n' +
      'Content-Length: 391\r\n' +
      'host: api.openai.com\r\n' +
      'Connection: close\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: [Function: nop],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 80,
      protocol: 'http:',
      options: [Object: null prototype],
      requests: [Object: null prototype] {},
      sockets: [Object: null prototype],
      freeSockets: [Object: null prototype] {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 2,
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'POST',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    path: 'https://api.openai.com/v1/chat/completions',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      socket: [Socket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 429,
      statusMessage: 'Too Many Requests',
      client: [Socket],
      _consuming: true,
      _dumped: false,
      req: [Circular *1],
      responseUrl: 'https://api.openai.com/v1/chat/completions',
      redirects: [],
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 22,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0,
      [Symbol(RequestTimeout)]: undefined
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: '127.0.0.1',
    protocol: 'http:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 391,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular *1],
      _currentUrl: 'https://api.openai.com/v1/chat/completions',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kBytesWritten)]: 0,
    [Symbol(kEndCalled)]: true,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'content-type': [Array],
      'user-agent': [Array],
      authorization: [Array],
      'content-length': [Array],
      host: [Array]
    },
    [Symbol(kUniqueHeaders)]: null
  },
  response: {
    status: 429,
    statusText: 'Too Many Requests',
    headers: {
      connection: 'close',
      'content-length': '207',
      'alt-svc': 'h3=":443"; ma=86400',
      'cf-cache-status': 'DYNAMIC',
      'cf-ray': '7e0b750d78872b53-LAX',
      'content-type': 'application/json; charset=utf-8',
      date: 'Mon, 03 Jul 2023 01:46:52 GMT',
      server: 'cloudflare',
      'strict-transport-security': 'max-age=15724800; includeSubDomains',
      vary: 'Origin',
      'x-request-id': '37654803750aed4c97969e4cdd845021'
    },
    config: {
      transitional: [Object],
      adapter: [Function: httpAdapter],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: Infinity,
      validateStatus: [Function: validateStatus],
      headers: [Object],
      method: 'post',
      proxy: [Object],
      data: '{"model":"gpt-3.5-turbo","messages":[{"role":"assistant","content":"嘿,早上好啊,chat"},{"role":"assistant","content":"你知道一首歌的歌词么?歌词如下:Fire.Fire draugen fire"},{"role":"assistant","content":"我们继续天"},{"role":"assistant","content":"我们继续聊天"},{"role":"assistant","content":"2356"}],"max_tokens":2048,"temperature":0.9,"stream":true}',
      url: 'https://api.openai.com/v1/chat/completions'
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: 391,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [Socket],
      _header: 'POST https://api.openai.com/v1/chat/completions HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/json\r\n' +
        'User-Agent: OpenAI/NodeJS/3.2.1\r\n' +
        'Authorization: Bearer ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■n52K9ENB\r\n' +
        'Content-Length: 391\r\n' +
        'host: api.openai.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'POST',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: 'https://api.openai.com/v1/chat/completions',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: '127.0.0.1',
      protocol: 'http:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kEndCalled)]: true,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype],
      [Symbol(kUniqueHeaders)]: null
    },
    data: { error: [Object] }
  },
  isAxiosError: true,
  toJSON: [Function: toJSON]
}

Hi whsabtechopenai

It is best practice to assume any given API call to any endpoint in any application will fail. You should build graceful error handling for such events, usually with exponential backoff for retries and keeping the user informed of the current status if appropriate.

It does indeed look like you ran into a temporary outage or reduction in performance at some point.

1 Like

A logic that tries to connect again after an increasing time can also help.

So try to get an answer, then wait a second, then try again, then wait two seconds and so on.

1 Like

FWIW… I use an exponential backoff policy of 2 seconds and then 5 seconds. That means I call the API and then will retry twice with an increasing delay. I haven’t seen a 429 make it through in over a month.

1 Like

The key here is the phrase “is not out of money”. The detective determines they are using a trial grant. Which has a limit of three request per minute, easy to hit.

Solution: Enter payment method for API.

You may need to upgrade your account.

Here is implementation of backoff, that works with axios,

AsyncFunction is the OpenAI’s function

//backoff.ts
type AsyncFunction = (...args: any[]) => Promise<any>;

export function retryWithExponentialBackoff(
    func: AsyncFunction,
    initialDelay: number = 1,
    exponentialBase: number = 2,
    jitter: boolean = true,
    maxRetries: number = 10,
): AsyncFunction {
    // Retry a function with exponential backoff
    return async function wrapper(...args: any[]) {
        // Initialize variables
        let numRetries = 0;
        let delay = initialDelay;

        // Loop until a successful response or maxRetries is hit or an exception is raised
        while (true) {
            try {
                return await func(...args);
            } catch (e) {
                // Retry on specific errors
                if (e && e === 429 || e === 500) {
                    // Increment retries
                    numRetries += 1;
                    // next retry in ${delay} seconds
                    console.log('\x1b[38;5;135m\x1b[40m%s\x1b[0m', `Retrying in ${delay} seconds... Retry attempt ${numRetries} of ${maxRetries}`);

                    // Check if max retries has been reached
                    if (numRetries > maxRetries) {
                        console.log(`Maximum number of retries (${maxRetries}) exceeded.`);
                    }
                    // Increment the delay
                    delay *= exponentialBase * (1 + (jitter ? Math.random() : 0));

                    // Sleep for the delay
                    await new Promise(resolve => setTimeout(resolve, delay * 1000));
                } else {
                    console.error('\x1b[38;5;124m\x1b[40m%s\x1b[0m', `Error number: ${e}`);
                    throw e;
                }
            }
        }
    }
}
1 Like

I am getting this message too-

statusCode: 429,
statusMessage: ‘Too Many Requests’,

Issue is only with gpt-4-1106-preview and not with gpt-3.5-turbo-16k

I was trying to process large data into chunks.

There is a token per minute limit (tpm). Maybe that’s the reason?

Hi - we are looking for AI freelance developers to work with on a project and thought you might be interested on recommend someone ? Thanks