A request waits about 25 seconds for Lumi’s answer. A task that takes longer, such as reading several pages, comes back with busy: true and an id, and keeps going.
Ask for the answer
GET /api/v1/chat/<id> (or /api/v1/robot/<id> for a robot) with the same key. The answer has the same shape as the POST:
busy: truewhile Lumi works,wait: trueandneedwhile it waits on the person,- then
reply, andfacefor a robot.
Every few seconds is fine. Asking costs no credits and doesn’t count toward the 40-a-minute limit. Ids are 12 hex characters; Lumi keeps the last 10 jobs, so an older id answers 404 no_job.
import os, time, requests
KEY = {"Authorization": "Bearer " + os.environ["LUMI_KEY"]}
r = requests.post("https://ai.avenpa.com/api/v1/chat", headers=KEY, timeout=40,
json={"text": "Compare the three cheapest flights to Denver on Friday"}).json()
while r.get("busy") or r.get("wait"):
time.sleep(5)
r = requests.get("https://ai.avenpa.com/api/v1/chat/" + r["id"], headers=KEY, timeout=20).json()
print(r["reply"])
Waiting on the person
need says what Lumi is waiting for:
need.kind |
|
|---|---|
ok |
The person has to approve a step, such as pressing a button that sends or buys something. |
password |
A password or code has to be typed. It is never taken through the API. |
hand |
The person has to do a step themselves. |
need.where is phone when Lumi sent a notification to their phone, or app when they should open the Lumi app. need.what describes the step. Once they have done it, the next GET carries on.
How a job ends
- Answered:
replywith the answer. - Stopped or failed:
200with areplythat says so, such as “It was stopped before it finished.”, andfailed: truewhen it ended in an error.
The whole task, step by step, is also in the person’s Lumi chat.