Quickstart
Send your first prompt to ChatGPT from a chosen country and read the answer and its cited sources in two minutes, with curl, Python or Node.js.
Run one prompt on one engine and read the result: the same call works as a ChatGPT scraper API for the answer and citations a person sees in the app. You need an API key: create one in the dashboard under API keys. Keys start with pk_live_.
1. Save your key
Shell
export PROMPTGALE_API_KEY=pk_live_...2. Ask and wait for the answer
POST /v1/sync/task runs the task and holds the request open until the answer is ready (up to 290 seconds).
curl
Shell
curl -X POST https://promptgale.com/v1/sync/task \
-H "Authorization: Bearer $PROMPTGALE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"taskType": "CHATGPT",
"payload": {
"prompt": "best crm for a small agency",
"country": "US",
"brand": "Acme"
}
}'Python
Python
import os
import requests
res = requests.post(
"https://promptgale.com/v1/sync/task",
headers={"Authorization": f"Bearer {os.environ['PROMPTGALE_API_KEY']}"},
json={
"taskType": "CHATGPT",
"payload": {"prompt": "best crm for a small agency", "country": "US", "brand": "Acme"},
},
timeout=300,
)
task = res.json()["data"]
print(task["status"], task["result"]["text"][:200])Node.js
Node.js
const res = await fetch('https://promptgale.com/v1/sync/task', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PROMPTGALE_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
taskType: 'CHATGPT',
payload: { prompt: 'best crm for a small agency', country: 'US', brand: 'Acme' },
}),
});
const { data: task } = await res.json();
console.log(task.status, task.result.text.slice(0, 200));3. Read the result
A 200 response carries the finished task. The answer is in data.result:
JSON
{
"success": true,
"data": {
"id": "tsk_8Jx0c2...",
"status": "COMPLETED",
"credits": 1,
"result": {
"text": "For a small agency, the most recommended CRMs are ...",
"sources": [
{ "position": 1, "url": "https://example.com/review", "domain": "example.com", "cited": true }
],
"analysis": {
"brands": [{ "name": "Acme", "mentioned": true, "rank": 1, "cited": true }]
}
}
}
}statusisCOMPLETEDorFAILED. A failed task is refunded and has anerrorobject instead of a result.- A
202response means the engine is still writing: keep theidand readGET /v1/tasks/{id}.
Next
- Many prompts, or work in a job queue: Tasks and Batches.
- Every field of the answer: Results.
- Another country, a US state or a city: Countries and locations.
- Using an agent instead of code: Connect an agent.
- More recipes (batches, countries, webhooks, CSV): Examples.
Last updated