Docs / API reference
GET /v1/job/{id}
Collect the result of an async check.
GET https://api.chatniai.com/v1/job/{job_id} with the same Authorization header.
curl https://api.chatniai.com/v1/job/3f2b9c1e-7d54-4a0b-9d3e-5f1a2c8e6b10 \
-H "Authorization: Bearer pij_live_YOUR_KEY"
States
| state | Meaning | What to do |
|---|---|---|
running | Still working. Includes elapsed_seconds. | Wait 10 to 15 seconds and ask again. |
done | Finished. The full answer is in result. | Read it and stop asking. |
failed | The check did not finish (for example it ran over 15 minutes). | Send the text again. A failed job is not charged. |
Good polling manners
- Ask every 10 to 15 seconds. Asking every second does not make it faster.
- Give up after about 15 minutes and treat it as failed.
- Store the
job_iduntil you have the result. If you lose it, you cannot ask for it again.
Who can read a job
Only a key from the account that started it. Any other key gets 404 no_such_job, even with a valid job ID.
# Python polling loop
import time, requests
H = {"Authorization": "Bearer " + KEY}
for _ in range(90): # about 15 minutes
r = requests.get(f"https://api.chatniai.com/v1/job/{job_id}", headers=H).json()
if r.get("state") == "done": print(r["result"]); break
if r.get("state") == "failed": print("failed"); break
time.sleep(10)