Skip to content

Polling for results

Each query creates one task per target app. Poll GET /v1/queries/{query_id} until status leaves pending.

status Meaning Final
pending At least one task is still in progress. No
completed All tasks have reached done, failed, or unavailable (individual tasks may still have failed). Yes
timeout deadline_at (roughly 6 hours) passed before all tasks finished. Yes
failed The query could not be queued; check error. No credits are charged. Yes
status Meaning Final
queued Waiting to run. Failed attempts return here for automatic retry. No
running Waiting for the app to answer. No
uploaded Raw response received; waiting to be parsed. No
parsing Extracting structured fields from the response. No
done result is populated. Only done tasks are charged. Yes
failed Processing failed after retries; check error. Yes
unavailable The target app did not respond (for example, due to overload). Retry later. Yes

Both completed and timeout queries can contain a mix of task outcomes, so inspect each task individually.

If a query reaches timeout while a task is already in uploaded or parsing, that task may still finish shortly afterward; fetch the query again if you need it.

  • Poll every 10 seconds. Tasks typically complete in about a minute, plus queue wait time under heavy load.
  • Each API key allows up to 300 read requests per minute; exceeding this returns 429 rate_limited with a Retry-After header.
  • For high-volume workloads, prefer callbacks or batch status checks via GET /v1/queries.
submit-and-wait.ts
// Node 24+ runs this file as it is. Submits a query, waits until it is final and prints the answers.
export {};
const API = "https://geo-api.geoeval.com";
const headers = { Authorization: `Bearer ${process.env.GEOEVAL_API_KEY}` };
interface Task {
app: string;
status: "queued" | "running" | "uploaded" | "parsing" | "done" | "failed" | "unavailable";
error: string | null;
result: { answer_markdown: string } | null;
}
interface Query {
query_id: string;
status: "pending" | "completed" | "timeout" | "failed";
tasks: Task[];
}
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
async function call(path: string, init: { method?: string; headers?: Record<string, string>; body?: string } = {}): Promise<Query> {
for (;;) {
const response = await fetch(API + path, { ...init, headers: { ...headers, ...init.headers } });
const data = (await response.json().catch(() => ({}))) as { code?: string; message?: string };
// 429 rate_limited and 503 are temporary: wait and repeat the same request
if (response.status === 503 || (response.status === 429 && data.code === "rate_limited")) {
await sleep(Number(response.headers.get("Retry-After") ?? 5) * 1000);
continue;
}
if (!response.ok) throw new Error(`${response.status} ${data.code}: ${data.message}`);
return data as Query;
}
}
let query = await call("/v1/queries", {
method: "POST",
// The same Idempotency-Key on a retry returns the same query instead of creating a second one
headers: { "Content-Type": "application/json", "Idempotency-Key": crypto.randomUUID() },
body: JSON.stringify({ query: "Which robot vacuum is the best choice?", apps: ["doubao", "kimi"] }),
});
// Poll until the query is final
while (query.status === "pending") {
await sleep(10_000);
query = await call(`/v1/queries/${query.query_id}`);
}
console.log("query", query.status);
for (const task of query.tasks) {
if (task.status === "done") console.log(task.app, task.result?.answer_markdown);
else console.log(task.app, task.status, task.error);
}