> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apiforgeo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Track a prompt set every day

> A scheduled job and about 20 lines of code.

To see how your visibility changes, run the same prompts on the same models every day. Store each result, then compare the days.

This recipe runs 3 prompts on 3 models: 9 tasks a day, $0.117 a day, about $3.51 for 30 days.

## 1. Create the tasks every day

```javascript daily.mjs theme={null}
// Run once a day, for example from cron: 0 6 * * * node daily.mjs
const PROMPTS = ["best running shoes for flat feet", "best trail running shoes", "most durable running shoes"];
const MODELS = ["chatgpt", "google-ai-mode", "gemini"];
const day = new Date().toISOString().slice(0, 10);

for (const [i, prompt] of PROMPTS.entries()) {
  for (const model of MODELS) {
    const res = await fetch("https://api.apiforgeo.com/v1/tasks", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.AFG_API_KEY}`,
        "Content-Type": "application/json",
        "Idempotency-Key": `running-${day}-${i}-${model}`, // a rerun the same day charges nothing more
      },
      body: JSON.stringify({
        prompt, model, country: "US", language: "en",
        webhookUrl: "https://example.com/hooks/apiforgeo",
        metadata: { promptSet: "running", day },
      }),
    });
    if (!res.ok) console.error(model, prompt, (await res.json()).error.code);
  }
}
```

* The `Idempotency-Key` names the day, the prompt and the model. If the job runs twice, or you rerun it after an error, no task is charged twice.
* `metadata` comes back on the task and in the webhook. Use it to file each result under its prompt set and day.

## 2. Store each result

The `webhookUrl` gets `task.completed` for each task. Verify the signature, then save what you need: the result is readable for 7 days only.

```javascript theme={null}
app.post("/hooks/apiforgeo", express.raw({ type: "application/json" }), async (req, res) => {
  if (!verifyWebhook(process.env.AFG_WEBHOOK_SECRET, req.headers, req.body.toString("utf8"))) return res.sendStatus(401);
  res.sendStatus(204);

  const { type, data: task } = JSON.parse(req.body);
  if (type !== "task.completed") return;
  await db.results.upsert({
    taskId: task.id, // the key: a retried delivery overwrites the same row
    day: task.metadata.day,
    model: task.model,
    prompt: task.prompt,
    brands: task.result.entities.filter((e) => e.type === "brand").map((e) => e.name),
    result: task.result,
  });
});
```

`verifyWebhook` is in [Verify webhook signatures](https://docs.apiforgeo.com/recipes/verify-webhooks.md).

## 3. Watch for failures

A failed task is refunded, and its webhook is `task.failed`. To find the failures of a day, list them:

```bash theme={null}
curl "https://api.apiforgeo.com/v1/tasks?status=failed&from=2026-11-19T00:00:00Z" \
  -H "Authorization: Bearer $AFG_API_KEY"
```

To try one again, create a new task with a new `Idempotency-Key`, for example with `-retry1` at the end.

Next: [Compare brands across models](https://docs.apiforgeo.com/recipes/compare-models.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.