PokeePokee Enterprise API
Cookbook

Long-running presentation generation

Persistent session, status polling via metadata, output retrieval.

PPT generation can take minutes. The agent should run independently of your client; you should be able to check progress and grab the output when ready.

Pattern

  1. Create a persistent session (won't auto-destroy).
  2. Send the message; let it run.
  3. Poll GET /v1/sessions/{id} for metadata updates.
  4. When done, download the output via the files API.

Code

import os, time, httpx

API = os.environ["POKEE_API"]
KEY = os.environ["POKEE_KEY"]
H   = {"Authorization": f"Bearer {KEY}", "Content-Type": "application/json"}

with httpx.Client(base_url=API, headers=H, timeout=httpx.Timeout(None)) as c:
    # 1. Persistent session — won't auto-destroy after idle
    sid = c.post("/v1/sessions",
                 json={"persistent": True, "ttl": 14400}).json()["id"]

    # 2. Kick off the long-running task (stream and consume, or fire and forget)
    with c.stream("POST", f"/v1/sessions/{sid}/messages",
                  json={"message": "Build a Temasek-style PPT on Q3 NVIDIA performance."}) as r:
        for line in r.iter_lines():
            if "message.completed" in line or "message.error" in line:
                break

    # 3. (Or, if you disconnected) poll metadata for progress
    while True:
        s = c.get(f"/v1/sessions/{sid}").json()
        if not s["busy"]:
            break
        status = s["metadata"].get("temasek_status", "running")
        print(f"  status: {status}")
        time.sleep(15)

    # 4. Download the result
    files = c.get(f"/v1/sessions/{sid}/files?path=output").json()
    pptx = next(f for f in files if f["name"].endswith(".pptx"))
    with c.stream("GET", f"/v1/sessions/{sid}/files/output/{pptx['name']}") as r, \
         open(pptx["name"], "wb") as out:
        for chunk in r.iter_bytes():
            out.write(chunk)

Why this works

  • persistent: true means the session survives long after a normal one would auto-destroy (5 min after the last response).
  • The agent keeps running even if you disconnect — the next call to /v1/sessions/{id} will see busy: true until the turn completes.
  • metadata is tool-specific. Long-running flows write progress hints there; watch for keys relevant to your workflow.

Cleanup

Destroy when done:

curl -X DELETE "$POKEE_API/v1/sessions/$SID" \
  -H "Authorization: Bearer $POKEE_KEY"

Or batch-clean idle sessions older than an hour:

curl -X DELETE "$POKEE_API/v1/sessions?status=idle&older_than=1h" \
  -H "Authorization: Bearer $POKEE_KEY"

On this page