Skip to main content
This guide shows you how to use the ChatGPT Scraper API with Node.js to programmatically collect AI-generated responses and structured metadata.

Installation

Install the axios HTTP client library:
npm install axios
Or if you’re using Yarn:
yarn add axios

Quick start

1

Import axios

Import the axios library at the top of your file.
const axios = require('axios');
2

Configure your request payload

Set up your payload with the prompt and optional parameters. Replace YOUR_API_KEY with your actual API key from the cloro dashboard.
const payload = {
  prompt: 'Compare the top 3 programming languages for web development in 2025',
  country: 'US',
  include: {
    markdown: true,
    rawResponse: true,
    searchQueries: true
  }
};
3

Make the API request

Send a POST request to the API endpoint and handle the response.
axios.post('https://api.cloro.dev/v1/monitor/chatgpt', payload, {
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
})
.then(response => {
  console.log(response.data);
})
.catch(error => {
  console.error('Error:', error);
});

Complete examples

const axios = require('axios');

const payload = {
  prompt: 'Compare the top 3 programming languages for web development in 2025',
  country: 'US',
  include: {
    markdown: true,
    rawResponse: true,
    searchQueries: true
  }
};

axios.post('https://api.cloro.dev/v1/monitor/chatgpt', payload, {
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
})
.then(response => {
  console.log(response.data);
})
.catch(error => {
  console.error('Error:', error);
});

Request parameters

Customize your API request using these parameters:
ParameterDescriptionDefault value
prompt*The prompt or question to send to ChatGPT (1-10,000 characters)
countryOptional country/region code for localized monitoring (e.g., US, GB, DE)
include.markdownInclude response in Markdown format when set to truefalse
include.rawResponseInclude raw streaming response events for debugging (+2 credits)false
include.searchQueriesInclude query fan-out ChatGPT used to generate response (+2 credits)false
The prompt parameter is mandatory. All other parameters are optional.

Handling the response

The API returns a JSON object with the following structure:
{
  status: 'success',
  result: {
    model: 'gpt-5-mini',
    text: 'When comparing programming languages for web development in 2025, three languages stand out...',
    markdown: '**When comparing programming languages for web development in 2025**, three languages stand out...',
    shoppingCards: [...],
    searchQueries: ['web development languages 2025'],
    rawResponse: [...]
  }
}
Access specific fields from the response:
const { status, result } = response.data;
const { model, text, markdown } = result;

console.log(`Model: ${model}`);
console.log(`Response: ${text}`);

Async/await pattern

Use async/await for cleaner, more readable code when working with promises.
const axios = require('axios');

async function queryChat(prompt) {
  try {
    const response = await axios.post(
      'https://api.cloro.dev/v1/monitor/chatgpt',
      {
        prompt: prompt,
        country: 'US',
        include: {
          markdown: true
        }
      },
      {
        headers: {
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json'
        }
      }
    );
    
    return response.data.result;
  } catch (error) {
    console.error('Failed to get ChatGPT response:', error.message);
    throw error;
  }
}

// Use the function
queryChat('What are the benefits of TypeScript?')
  .then(result => console.log(result.text))
  .catch(error => console.error(error));

Timeout configuration

Set an appropriate timeout (120-180 seconds) when making requests, as ChatGPT responses may take time to generate depending on complexity.
const response = await axios.post(
  'https://api.cloro.dev/v1/monitor/chatgpt',
  payload,
  {
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    timeout: 180000  // 3 minutes in milliseconds
  }
);
For production use, implement a retry mechanism instead of relying solely on timeouts, as the cloro system retries automatically.

Error handling best practices

Implement robust error handling to manage different failure scenarios:
const axios = require('axios');

async function makeChatGPTRequest(payload, maxRetries = 3) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      const response = await axios.post(
        'https://api.cloro.dev/v1/monitor/chatgpt',
        payload,
        {
          headers: {
            'Authorization': 'Bearer YOUR_API_KEY',
            'Content-Type': 'application/json'
          },
          timeout: 180000
        }
      );
      
      return response.data;
      
    } catch (error) {
      // Handle timeout errors
      if (error.code === 'ECONNABORTED') {
        console.log(`Attempt ${attempt + 1} timed out`);
        if (attempt < maxRetries - 1) {
          await new Promise(resolve => setTimeout(resolve, 5000));
          continue;
        }
      }
      
      // Handle HTTP errors
      if (error.response) {
        const status = error.response.status;
        
        if (status === 429) {
          console.log('Rate limit reached, waiting before retry...');
          await new Promise(resolve => setTimeout(resolve, 10000));
          continue;
        }
        
        if (status >= 500 && attempt < maxRetries - 1) {
          console.log(`Server error on attempt ${attempt + 1}`);
          await new Promise(resolve => setTimeout(resolve, 5000));
          continue;
        }
        
        throw new Error(`HTTP ${status}: ${error.response.data.message || 'Request failed'}`);
      }
      
      // Handle network errors
      if (error.request) {
        console.log(`Network error on attempt ${attempt + 1}`);
        if (attempt < maxRetries - 1) {
          await new Promise(resolve => setTimeout(resolve, 5000));
          continue;
        }
      }
      
      throw error;
    }
  }
  
  throw new Error('Max retries reached');
}

// Usage example
const payload = {
  prompt: 'Your prompt here',
  country: 'US'
};

makeChatGPTRequest(payload)
  .then(result => {
    console.log(result.result.text);
  })
  .catch(error => {
    console.error('Failed to get response:', error.message);
  });

Promise vs async/await

You can use either promises or async/await depending on your preference:
axios.post('https://api.cloro.dev/v1/monitor/chatgpt', payload, config)
  .then(response => {
    console.log(response.data);
    return response.data;
  })
  .then(data => {
    // Process data
    console.log(data.result.text);
  })
  .catch(error => {
    console.error('Error:', error);
  });
Always verify the status field in the response is "success" before accessing the result data.

Next steps

Build docs developers (and LLMs) love