Skip to content

Use case

Build an AI visibility tool on an API

An AI visibility (GEO) tool asks AI answer engines the prompts buyers ask, from the markets they buy in, and measures how often and how well a brand shows up. With PromptGale the collection step is one API: queue prompts times engines times countries as a batch, receive each answer with its sources and a brand analysis by webhook, and compute the metrics in your own database.

Updated

What does the architecture look like?

  1. Prompt set. Per brand: 20 to 200 prompts a buyer would type, grouped by topic and intent, each with the markets it matters in. Keep prompts stable between runs, or the trend means nothing.
  2. Engines and countries. Pick from what GET /v1/capabilities lists: right now ChatGPT, Gemini, Perplexity, Bing Copilot Search, Meta AI, Google AI Overview, and Google AI Mode. GET /v1/countries?taskType=... says where each one is served.
  3. A scheduled run. Once a week (or a day), send one POST /v1/batches with every prompt times engine times country, the brand, its competitors and a webhookUrl.
  4. A webhook receiver. It verifies the signature, then stores the answer, its sources and analysis.brands. Deduplicate on the task id: retries deliver the same task again.
  5. A metrics job. When batch.completed arrives, compute the metrics below for the run and store them per brand, engine, country and topic.
  6. The product. Charts of the metrics over time, the answers themselves, and the cited pages a client could get onto.
  • Collection

    PromptGale: batches, browsers, countries, retries, refunds of failed tasks, signed webhooks.

  • Storage

    Yours: answers, sources and brand results per task, keyed by task id and run.

  • Metrics and UI

    Yours: the SQL below and whatever you show your users.

Which metrics should an AI visibility tool compute?

Four numbers cover most of what clients ask. Define them once, on completed answers only (failed tasks are refunded and carry no answer), and report each with its sample size.

Metric definitions
MetricDefinitionFrom the result
Mention rateAnswers that name the brand, divided by completed answers, as a percent.analysis.brands[].mentioned
Share of voiceThe brand's mentions divided by the mentions of every tracked brand, as a percent. Per answer the API already gives 100 times its mentions over all brand mentions.mentions, shareOfVoice
Citation shareCited sources on the brand's domains divided by all cited sources, as a percent.sources[].cited, cited, citedUrls; or analysis.sources[].brand
PositionAverage rank over the answers that mention the brand (1 is named first). Always show it next to mention rate: a brand named once, first, has a perfect position.rank
metrics.sql (PostgreSQL)
-- One row per completed answer and tracked brand, filled by the webhook receiver:
-- answers(task_id, run_id, engine, country, prompt, completed_at)
-- brand_results(task_id, brand, role, mentioned, mentions, rank, cited)
-- answer_sources(task_id, domain, cited, brand)   -- brand: the brand the domain belongs to, or null

-- Mention rate and average position, per brand, engine and country, for one run
SELECT b.brand, a.engine, a.country,
       round(100.0 * avg(CASE WHEN b.mentioned THEN 1 ELSE 0 END), 1) AS mention_rate_pct,
       round(avg(b.rank) FILTER (WHERE b.mentioned), 2)               AS avg_position,
       round(100.0 * avg(CASE WHEN b.rank = 1 THEN 1 ELSE 0 END), 1)  AS first_place_pct
FROM brand_results b JOIN answers a USING (task_id)
WHERE a.run_id = $1
GROUP BY b.brand, a.engine, a.country;

-- Share of voice: a brand's mentions over the mentions of every tracked brand
SELECT b.brand,
       round(100.0 * sum(b.mentions) / nullif(sum(sum(b.mentions)) OVER (), 0), 1) AS share_of_voice_pct
FROM brand_results b JOIN answers a USING (task_id)
WHERE a.run_id = $1
GROUP BY b.brand;

-- Citation share: cited sources on a brand's domains over all cited sources
SELECT s.brand,
       round(100.0 * count(*) / nullif(sum(count(*)) OVER (), 0), 1) AS citation_share_pct
FROM answer_sources s JOIN answers a USING (task_id)
WHERE a.run_id = $1 AND s.cited
GROUP BY s.brand;

Every analysis field is described in Results. Pass brandDomains so citations on the brand's own sites count, and up to 50 competitors. See also share of voice and mention rate.

How do I send the prompts?

One batch per run. Every item is checked before anything is queued, so one bad item refuses the batch and names it. An idempotencyKey per run makes a retried request return the same batch instead of a second one.

POST /v1/batches
curl -X POST https://promptgale.com/v1/batches \
  -H "Authorization: Bearer $PROMPTGALE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "items": [
      { "customId": "p1-chatgpt", "taskType": "CHATGPT", "payload": {"prompt": "best coffee subscription for home espresso", "country": "US", "brand": "Acme Coffee", "competitors": ["Northwind Roasters", "Bluebird Beans"]} },
      { "customId": "p1-gemini", "taskType": "GEMINI", "payload": {"prompt": "best coffee subscription for home espresso", "country": "US", "brand": "Acme Coffee", "competitors": ["Northwind Roasters", "Bluebird Beans"]} },
      { "customId": "p1-perplexity", "taskType": "PERPLEXITY", "payload": {"prompt": "best coffee subscription for home espresso", "country": "US", "brand": "Acme Coffee", "competitors": ["Northwind Roasters", "Bluebird Beans"]} },
      { "customId": "p2-chatgpt", "taskType": "CHATGPT", "payload": {"prompt": "coffee subscription for a moka pot", "country": "US", "brand": "Acme Coffee", "competitors": ["Northwind Roasters", "Bluebird Beans"]} },
      { "customId": "p2-gemini", "taskType": "GEMINI", "payload": {"prompt": "coffee subscription for a moka pot", "country": "US", "brand": "Acme Coffee", "competitors": ["Northwind Roasters", "Bluebird Beans"]} },
      { "customId": "p2-perplexity", "taskType": "PERPLEXITY", "payload": {"prompt": "coffee subscription for a moka pot", "country": "US", "brand": "Acme Coffee", "competitors": ["Northwind Roasters", "Bluebird Beans"]} }
    ],
    "webhookUrl": "https://example.com/hooks/promptgale",
    "idempotencyKey": "weekly-2026-11-27"
  }'

Up to 10,000 items per batch. Starter batches take up to 100 items; location grids need a plan above Starter. Follow it with GET /v1/batches/{id} (counts, percent done, credits held and charged) or read items with GET /v1/batches/{id}/items?include=result. See Batches.

How do I receive and store the answers?

Each finished task is POSTed to your webhookUrl, signed with HMAC-SHA256. Verify over the raw body, then store what the metrics need. Deliveries are retried 4 more times (after 2, 4, 8 and 16 minutes) until you answer 2xx.

webhook.js (Node.js, Express)
import crypto from 'node:crypto';
import express from 'express';

const app = express();
const SECRET = process.env.PROMPTGALE_SIGNING_SECRET; // shown once when the API key is created

app.post('/hooks/promptgale', express.raw({ type: 'application/json' }), async (req, res) => {
  const raw = req.body.toString('utf8');
  const timestamp = req.header('promptgale-webhook-timestamp');
  const given = (req.header('promptgale-webhook-signature') ?? '').replace(/^v1,/, '');
  const event = JSON.parse(raw);
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return res.sendStatus(400);
  // Task events are signed over taskId.timestamp.body; batch.completed over batchId.timestamp.body.
  const expected = crypto.createHmac('sha256', SECRET).update(`${event.data.id}.${timestamp}.${raw}`).digest('base64');
  if (given.length !== expected.length || !crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected))) return res.sendStatus(401);

  if (event.event === 'task.completed') {
    const task = event.data;
    const brands = task.result.analysis?.brands ?? [];
    await saveAnswer({
      taskId: task.id, // deduplicate on it: retries deliver the same task again
      engine: task.taskType,
      country: task.country,
      prompt: task.payload.prompt,
      text: task.result.text,
      sources: task.result.sources.map((s) => ({ domain: s.domain, url: s.url, cited: s.cited })),
      brands: brands.map((b) => ({ name: b.name, mentioned: b.mentioned, rank: b.rank, cited: b.cited, shareOfVoice: b.shareOfVoice })),
    });
  }
  res.sendStatus(200);
});

Signature details and a Python version: Webhooks.

What does it cost per 1,000 answers?

Cost per 1,000 completed answers, by plan (computed)
EngineCredits per answerStarter ($19.00/mo)Growth ($79.00/mo)Pro ($299.00/mo)Scale ($999.00/mo)
ChatGPT1.5$14.25$11.85$8.97$7.49
Gemini1.5$14.25$11.85$8.97$7.49
Perplexity1.5$14.25$11.85$8.97$7.49
Bing Copilot Search1$9.50$7.90$5.98$5.00
Meta AI2$19.00$15.80$11.96$9.99
Google AI Overview1$9.50$7.90$5.98$5.00
Google AI Mode1$9.50$7.90$5.98$5.00

Computed: credits per answer times 1,000 times the plan's price per credit (plan price divided by its monthly credits). A US state or map point adds 1 credit per task. Failed tasks are refunded, so they cost nothing. Taxes not included. Current plans are on Pricing.

A worked example (computed): 50 prompts on 7 engines in 3 countries, once a week, is 4,200 answers and 5,700 credits a month. That fits in the Growth plan (10,000 credits for $79.00 a month).

Questions, answered

Do I need to run my own browsers or proxies?

No. PromptGale opens each engine in a real browser from the country you pick and returns JSON. Your code sends batches and stores results.

Does the brand analysis cost extra?

No. Pass brand, brandDomains and competitors in the payload and analysis.brands comes with the answer at the engine price.

How many prompts can I send at once?

Up to 10,000 items in one batch; larger runs are several batches. Starter batches take up to 100 items; location grids need a plan above Starter. How fast a batch runs depends on your plan concurrency.

How do I compare countries?

Send the same prompt with different payload.country values, and store country with each answer. Mention rate per country is then one GROUP BY.

Run your first prompt in a minute.