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

stateMeaningWhat to do
runningStill working. Includes elapsed_seconds.Wait 10 to 15 seconds and ask again.
doneFinished. The full answer is in result.Read it and stop asking.
failedThe check did not finish (for example it ran over 15 minutes).Send the text again. A failed job is not charged.

Good polling manners

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)