GLKB iconAPI Docs

Batch Endpoint

Run a prompt template across a list of entities and stream back cited answers.

Endpoint

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

Authentication

Authorization: Bearer <GLKB_API_KEY>

Path parameters

ParameterTypeDescription
user_idstringYour GLKB user identifier

Request body

json
{
  "items": ["TP53", "KRAS", "BRCA1"],
  "prompt_template": "What is the role of {item} in cancer? Give 2 PMIDs.",
  "concurrency": 5
}
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

Per-item 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

Error codes

CodeMeaning
400Bad request — missing or invalid parameters
401Unauthorized — missing or invalid API key
422Unprocessable — prompt template missing {item}, or items list empty
429Rate limit exceeded
500Internal server error

Code examples

python
import requests, json, os

with requests.post(
    "https://api.glkb.dev/apps/glkb/users/me/batch",
    headers={"Authorization": f"Bearer {os.environ['GLKB_API_KEY']}"},
    json={
        "items": ["TP53", "KRAS", "BRCA1"],
        "prompt_template": "Role of {item} in cancer? Up to 2 PMIDs.",
        "concurrency": 5,
    },
    stream=True,
    timeout=300,
) as r:
    r.raise_for_status()
    for line in r.iter_lines():
        if line and line.startswith(b"data:"):
            event = json.loads(line[5:])
            if event["status"] == "done":
                print(f"{event['item']}: {event['response']}")
bash
curl -N -X POST "https://api.glkb.dev/apps/glkb/users/me/batch" \
  -H "Authorization: Bearer $GLKB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "items": ["TP53", "KRAS", "BRCA1"],
    "prompt_template": "Role of {item} in cancer? Up to 2 PMIDs.",
    "concurrency": 5
  }'