Chat and runs
POST/v1/chat
Ask Panlytics a question about a shop. The answer comes back as a run.
What it does
Starts the same assistant the app has, counted against the shop's daily AI budget and the limit of 30 runs an hour per person. Read the run with GET /v1/runs/{id}, or follow it with GET /v1/runs/{id}/stream. Anything the assistant proposes to do waits for a person to approve it in the app: a key can never approve it. Send an Idempotency-Key header so a retry never starts a second run.
Who may call it
A key whose maker's role holds agents (ask the agents and approve what they do), after the fence, for the shop or category it names.
Request
POST https://panlytics.net/api/v1/chatParameters
| Name | In | Type | Required | What it is |
|---|---|---|---|---|
Authorization | header | string | Yes | Bearer, a space, then the key. |
Idempotency-Key | header | string | No | Any string up to 255 characters, new for each new request. The same key with the same request within 24 hours answers with the first answer again and does nothing twice. |
Body
Sent as application/json.
| Field | Type | Required | What it is |
|---|---|---|---|
shopId | integer | Yes | The shop the question is about. Its daily AI budget pays for the run. |
prompt | string | Yes | The question, in plain words. |
categoryId | integer | No | A category of that shop, to ask about its newest report. |
threadId | string (UUID) | No | A conversation to continue: any conversation in the company that the key's maker may open. |
Example request
curl -X POST https://panlytics.net/api/v1/chat \
-H "Authorization: Bearer $PANLYTICS_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"shopId": 12,
"prompt": "Which drinks ran out most often last month?"
}'import os
import uuid
import requests
response = requests.post(
"https://panlytics.net/api/v1/chat",
headers={"Authorization": f"Bearer {os.environ['PANLYTICS_KEY']}", "Idempotency-Key": str(uuid.uuid4())},
json={
"shopId": 12,
"prompt": "Which drinks ran out most often last month?"
},
timeout=60,
)
response.raise_for_status()
print(response.json())const response = await fetch("https://panlytics.net/api/v1/chat", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.PANLYTICS_KEY}`,
"Idempotency-Key": crypto.randomUUID(),
"Content-Type": "application/json",
},
body: JSON.stringify({
"shopId": 12,
"prompt": "Which drinks ran out most often last month?"
}),
});
if (!response.ok) throw new Error(`Panlytics answered ${response.status}`);
console.log(await response.json());Response
201: Created. The answer is what was made, as JSON.
| Field | Type | Always there | What it is |
|---|---|---|---|
runId | string (UUID) | Yes | The run's id. Read it with GET /v1/runs/{id}. |
threadId | string (UUID) | Yes | The conversation the run belongs to. Send it as threadId to ask a follow-up. |
status | string (always "queued") | Yes | Always queued: the run has been handed to the engine. |
Example response
{
"runId": "6f1c2b9e-2d4f-4f7e-9a51-0c3b8e7d1a20",
"threadId": "0b9e4a3c-71d2-4c55-8f0e-3a6d2b1c9e47",
"status": "queued"
}Errors
A refusal is JSON with a code, a sentence in error, and a requestId when the fault is ours. Read the code, not the sentence. Every code is listed on Errors.
| Status | Code | When | What to do |
|---|---|---|---|
| 400 | api.invalid | A path id, a query parameter, a header or a body field is missing or not valid. detail names the field. | Read that endpoint in the API reference, correct the field and call again. |
| 400 | bad_request.said | Change it and try again. | |
| 401 | api.key_missing | The call had no Authorization header. | Send the key in the Authorization header as Bearer, then call again. |
| 401 | api.key_refused | The key is wrong, revoked, past its end, or its maker or company no longer allows it (developer mode off, the maker removed or switched off, or the maker's role lost the developer ability). | Ask the person who gave you the key to make a new one. |
| 401 | api.wrong_key_kind | This key does not open these endpoints. | Use the key these endpoints were made for, or ask the person who gave you the key. |
| 403 | refused | The key's maker may not do this here: their role lacks the ability, or the shop or category is outside their reach. | Ask the CEO for a role that allows it, or call it for a shop or category the role reaches. |
| 403 | auth.not_fresh | This step needs you to prove it is you. | Confirm your password or passkey, then try again. |
| 403 | refused.said | Ask an owner of your company if you need this. | |
| 404 | not_found.said | Nothing with that id in the key's company. An id of another company answers the same. | Check the id. List the shop or category it belongs to and take the id from there. |
| 409 | report.none | There is no report yet to work from. | Upload a report first, with POST /v1/shops/{id}/reports. |
| 409 | store.none | No shop is open in this session. | Choose a shop from the switcher and try again. |
| 409 | conflict.said | The shop already has a supplier with that name. | Use another name, or change the supplier that has it. |
| 409 | api.idempotency_conflict | That Idempotency-Key was sent before with a different request. | Send a new key with a new request, or send the first request again unchanged. |
| 409 | api.idempotency_busy | The first request with that Idempotency-Key is still running. | Wait a few seconds, then send it again. |
| 429 | api.rate_limited | The key made more than 120 calls in this minute. Wait the seconds in Retry-After. | Wait the seconds in Retry-After, then call again. |
| 429 | api.ai_budget | The shop has used today's AI budget. Retry-After holds the seconds until midnight UTC. | Try again after midnight UTC, or ask an owner to raise the daily limit in AI settings. |
| 429 | net.rate_limited | The key's maker started 30 runs in the last hour. | Wait a few minutes, then start the run again. The answer carries limit: 30. |
| 500 | server | Something failed on our side. The answer carries a requestId to quote. | Try again in a minute; if it keeps happening, report it. |
| 503 | developer.unavailable | API keys are not set up on this deployment yet. | Report it, and we will switch them on. |
| 503 | agent.unreachable | The assistant is not answering right now. | Everything else still works; try the assistant again in a few minutes. |