GLKB iconAPI Docs

The Batch Pattern

One prompt, run across every item in your list.

How it works

A batch request has two parts: items and prompt_template. The agent runs the prompt once per item, substituting {item} each time, and streams results back as they complete.

["TP53", "KRAS", "BRCA1"]  ×  "What is the role of {item} in cancer? Give 2 PMIDs."
        ↓                                   ↓                                ↓
   cited answer                        cited answer                    cited answer

Endpoint

POST /apps/glkb/users/{user_id}/batch

Request parameters

ParameterTypeRequiredDescription
itemsarray of stringsYesEntities to query — genes, variants, drugs, proteins, or any term the knowledge graph recognizes
prompt_templatestringYesPrompt run for each item. Must include {item} as a placeholder
concurrencyintegerNoNumber of items processed in parallel. Default 5, max 50

Response format

The API responds as a Server-Sent Events stream. Each event is a JSON object on a data: line.

Per-item result (status: "done")

Emitted once per item as it completes.

json
{
        "status": "done",
        "index": 0,
        "item": "TP53",
        "response": "TP53 encodes a tumor suppressor mutated in over 50% of cancers [PMID 28982660]."
}
FieldTypeDescription
statusstring"done"
idxintegerPosition of the item in the original list
itemstringThe entity that was queried
responsestringThe agent's cited answer

Completion result (status: "complete")

Emitted once after all items finish.

json
{
        "status": "complete",
        "succeeded": 3,
        "total": 3
}
FieldTypeDescription
statusstring"complete"
succeededintegerNumber of items that returned a result
totalintegerTotal items submitted

Parsing the stream

python
for line in response.iter_lines():
        if line and line.startswith(b"data:"):
                event = json.loads(line[5:])
                if event["status"] == "done":
                        print(f"{event['item']}: {event['response']}")
                elif event["status"] == "complete":
                        print(f"Done - {event['succeeded']}/{event['total']} succeeded")

Throughput

At the default concurrency of 5, expect roughly 50 items per minute. Set concurrency higher for large lists — a batch of 1,500 genes at concurrency=50 completes in approximately 30 minutes.