Skip to main content
This guide shows you how to use the ChatGPT Scraper API with cURL to programmatically collect AI-generated responses from the command line or shell scripts.

Quick start

1

Set your API key

Replace YOUR_API_KEY with your actual API key from the cloro dashboard.
2

Make a basic request

Send a POST request to the ChatGPT API endpoint.
3

Process the response

The API returns a JSON response that you can pipe to other commands or save to a file.

Complete example

Request headers

You must include these headers in every request:
The Authorization header must use the Bearer scheme with your API key. The Content-Type header tells the API that you’re sending JSON data.

Formatting the JSON payload

When using cURL, you have several options for formatting your JSON payload:

Inline JSON

For simple requests, you can include the JSON directly in the command:

Multi-line JSON

For better readability, use multi-line formatting:

External JSON file

For complex payloads or reusable requests, use an external file:
Using external JSON files makes it easier to maintain complex payloads and reuse them across multiple requests.

Request parameters

Customize your API request using these parameters in the JSON payload:
The prompt parameter is mandatory. All other parameters are optional.

Handling the response

The API returns a JSON response with this structure:

Save response to file

Pretty print with jq

Extract specific fields

Timeout configuration

Set an appropriate timeout (120-180 seconds) when making requests, as ChatGPT responses may take time to generate depending on complexity.
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 in your shell scripts:

Checking response status

Always verify the HTTP status code and the status field:

Shell script integration

Here’s a complete example of integrating the API into a shell script:
Always validate the response structure and check for the success status before attempting to access nested fields.

Next steps