How to post 2000000 records into KV storage by calling post API

We have 2000000 records & store in json array then trying to post data into KV storage using worker.js, but not able to post data by calling post json API. Whenever posting large numbers of records showing CPU time limit issues & data not saved. Please check my below code & suggest me that where is wrong. Actually whenever run below api so not able to fetching body content, that’s why data not posting.

const corsHeaders = {
‘Access-Control-Allow-Origin’: ‘*’,
‘Access-Control-Allow-Methods’: ‘GET,HEAD,POST,OPTIONS’,
‘Access-Control-Max-Age’: ‘86400’,
async function gatherResponse(response) {
const { headers } = response;
const contentType = headers.get(‘content-type’) || ‘’;
if (contentType.includes(‘application/json’)) {
return JSON.stringify(await response.json());
} else if (contentType.includes(‘application/text’)) {
return response.text();
} else if (contentType.includes(‘text/html’)) {
return response.text();
} else {
return response.text();

async function handleRequest() {
const init = {
body: JSON.stringify(body),
method: ‘POST’,
headers: {
‘content-type’: ‘application/json;charset=UTF-8’,
const response = await fetch(url, init);
const results = await gatherResponse(response);
return new Response(results, init);
addEventListener(‘fetch’, event => {
return event.respondWith(handleRequest());
Please check my KV storage format is it correct or not

As per workers documentation

The bulk API can accept up to 10,000 KV pairs at once.

So if you are wanting to push 2,000,000, then you are going to need to make multiple calls.

Interesting to note this is twice the number you mentioned in I have 1000000 records in database table.