Developers
Call your agent from your own code
Every agent you deploy on Provisio Sigil can answer messages sent from your own server or app. You send a message over HTTPS with a secret key, and the agent replies the way it does in your Run tab, with the same guardrails.
This page covers everything you need: getting a key, sending a message, reading the reply, streaming, and what each error means.
Before you start
Your agent needs to be deployed. Keys work only for a live agent, so the button that creates one turns on once the agent is deployed.
1. Get a key
- Open your agent and go to its API tab.
- Click Generate API Key.
- Copy or download the key right away. It is shown once.
About keys:
- A key starts with
piq_sk_and belongs to one agent. It works only for that agent. - You can create several keys. Each one is listed under Active keys.
- Click Revoke next to a key to switch it off. It stops working on the next request.
- This is a secret key. Keep it on your server, never in code that runs in a visitor’s browser or app.
The API tab also shows sample code in cURL, Python and JavaScript with your key and your agent address filled in.
2. Send a message
POST https://app.provisiosigil.com/deploy/chat/{agent-address}
Headers
| Header | Value |
|---|---|
Content-Type | application/json |
x-api-key | your secret key |
The agent address is the name-like ID at the end of the URL in your sample code, for example customer_support_a1b2c3d4. Copy it from the API tab.
Body
| Field | Type | Required | What it does |
|---|---|---|---|
message | string | Yes | What the person said to your agent. |
sessionId | string | Recommended | Keeps messages in one conversation, so the agent remembers what was said earlier. |
timezone | string | No | The time zone of the person chatting, as an IANA name such as America/Chicago. The agent uses it to answer date and time questions for that person’s day. |
Conversations and sessionId
To continue a conversation, send the same sessionId with each message and the agent picks up where it left off. Create a new ID for each new conversation, such as a random UUID, and give each person their own.
- Always send a
sessionId, with a different one for each person. - Keep your own copy of any conversation you need to retain, such as transcripts.
Time zone
Send the time zone of the person chatting, not the time zone of your server. In a browser, this line returns it:
Intl.DateTimeFormat().resolvedOptions().timeZone
Pass that value to your server with the message, then include it as timezone in the call.
If you leave it out, or send a value that is not an IANA time zone name, the call still works and the agent uses UTC. For an agent you brought from elsewhere (bring your own agent), the time zone is used by Provisio Sigil’s own checks and is not forwarded to your agent.
3. Read the reply
A successful call returns HTTP 200 with JSON like this:
{
"output": "Your agent's answer.",
"sessionId": "your sessionId",
"complianceDegraded": null
}
| Field | What it holds |
|---|---|
output | The agent’s answer, as text. |
sessionId | The sessionId you sent. If you sent none, a new one is made for this reply; send it back to continue the conversation. |
complianceDegraded | Usually null or false. true marks a message answered in safe mode. Worth logging. |
Some 200 replies are the agent saying no, or asking to try again. They arrive in output like any other answer.
- An answer that starts with
I'm sorry, I'm not able to help with that request.means the agent’s guardrails stopped this message or its answer. It may add a sentence about what the agent can help with. Rephrasing won’t change a guardrail. - Personal details the agent may not share can appear as
(hidden for privacy)inside an otherwise normal answer. I can't answer right now. Please try again in a few minutes.means the agent is briefly unavailable. Try again in a few minutes.- If the agent cannot finish, for example the request took too long,
outputholds a short message saying so.
4. Streaming (optional)
To show the answer as it is written, call the streaming address instead, with the same headers and body:
POST https://app.provisiosigil.com/deploy/chat/{agent-address}/stream
The reply is a stream of server-sent events (Content-Type: text/event-stream). Each event looks like this:
event: token
data: {"type": "token", "data": "Hello", "metadata": {}}
| Event | What it means |
|---|---|
token | A piece of the answer. Join the data values in order to build the full answer. |
tool_start, tool_end | The agent is using one of its connected tools. data holds the tool’s name. Show a “working on it” state if you like. |
heartbeat | Keeps the connection open during long pauses. Ignore it. |
error | Something went wrong after the stream started. data holds a short message you can show. |
done | The answer is complete. metadata can include session_id, token_usage and latency_ms. |
Two things to plan for:
- Agents with compliance checking turned on send the whole answer as one
tokenevent at the end, because every answer is checked before anyone sees it. - Errors before the stream opens (such as
401,402,429and503) come back as normal HTTP errors, described below. Once the stream is open, a problem arrives as anerrorevent followed bydone.
5. Errors
Errors come back as JSON in this shape:
{
"error": {
"code": "UNAUTHORIZED",
"message": "A short description.",
"details": null,
"retryable": false,
"request_id": "…",
"trace_id": "…"
}
}
If you contact support, include the request_id. One exception to the shape: a 429 returns the same fields at the top level, without the outer error wrapper.
| Status | code | What it means | What to do |
|---|---|---|---|
400 | INVALID_URL | Bring your own agent only. The address your imported agent points to is not allowed. | Change your imported agent’s address. Trying again won’t help. |
401 | UNAUTHORIZED | The key is missing, wrong, revoked or expired, or belongs to a different agent. Also returned when the agent address is wrong or the agent is not deployed. | Check the key and the agent address against the API tab, and that the agent is deployed. If you lost the key, generate a new one. |
402 | LIMIT_EXCEEDED | The agent owner’s plan has used all its agent runs. Each message sent to the agent counts as one run for the owner. | Upgrade the plan. The message field explains the limit. |
422 | VALIDATION_422_SCHEMA | The body isn’t valid, for example message is missing. | Fix the body. details.errors lists each problem field. |
429 | RATE_LIMIT | Too many requests. With a valid key the limit is 60 requests per minute per key for each agent address. Requests without a valid key have a lower limit. | Wait the number of seconds in the Retry-After header, then try again. |
500 | INTERNAL_ERROR | Something unexpected went wrong on our side. | Try again once. If it repeats, contact support with the request_id. |
503 | SERVICE_UNAVAILABLE | The agent can’t run right now, for example one of its connected tools couldn’t be reached. retryable is true. | Try again shortly, and check the agent’s connections. details.user_message holds a message you can show to the person. |
6. Examples
Replace YOUR_AGENT_ADDRESS with your agent’s address from the API tab. Keep your key in an environment variable named PIQ_API_KEY for cURL, or replace YOUR_API_KEY in the Python and JavaScript examples.
cURL
# One id per person. Reuse it to continue the conversation.
curl -X POST \
https://app.provisiosigil.com/deploy/chat/YOUR_AGENT_ADDRESS \
-H "Content-Type: application/json" \
-H "x-api-key: $PIQ_API_KEY" \
-d '{"message": "Hello", "sessionId": "'"$(uuidgen)"'"}'
Python
import uuid
import requests
# One id per person. Reuse it to continue the conversation.
session_id = str(uuid.uuid4())
response = requests.post(
"https://app.provisiosigil.com/deploy/chat/YOUR_AGENT_ADDRESS",
headers={
"Content-Type": "application/json",
"x-api-key": "YOUR_API_KEY",
},
json={"message": "Hello", "sessionId": session_id},
)
print(response.json())
JavaScript
// One id per person. Reuse it to continue the conversation.
const sessionId = crypto.randomUUID();
const response = await fetch(
"https://app.provisiosigil.com/deploy/chat/YOUR_AGENT_ADDRESS",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": "YOUR_API_KEY",
},
body: JSON.stringify({ message: "Hello", sessionId }),
},
);
const data = await response.json();
console.log(data);
Each example makes a new ID. Store it for that person and send the same one with their next message, as described in section 2.
A fuller Python example with a unique conversation ID, the person’s time zone and basic error handling:
import os
import uuid
import requests
API_KEY = os.environ["PROVISIO_SIGIL_API_KEY"] # keep the key out of your code
URL = "https://app.provisiosigil.com/deploy/chat/YOUR_AGENT_ADDRESS"
session_id = str(uuid.uuid4()) # one per conversation
def ask(message, visitor_timezone=None):
body = {"message": message, "sessionId": session_id}
if visitor_timezone:
body["timezone"] = visitor_timezone # for example "America/Chicago"
response = requests.post(
URL,
headers={"Content-Type": "application/json", "x-api-key": API_KEY},
json=body,
timeout=130,
)
if response.status_code == 200:
return response.json()["output"]
if response.status_code == 429:
wait = response.headers.get("Retry-After")
raise RuntimeError(f"Rate limited, retry after {wait} seconds")
payload = response.json()
error = payload.get("error", payload)
raise RuntimeError(f"{response.status_code} {error.get('code')}: {error.get('message')}")
print(ask("What's on my calendar today?", "America/Chicago"))