Event triggers
An event trigger starts a run of a chat when something outside sends it an event: a pull request on GitHub, a build that fails, a script that calls curl. The sender posts to a URL that belongs to the trigger, and the trigger’s own secret is the credential. This page shows how to create one, how a sender signs a call, and what limits apply.
For reminders that follow the things of an add-on, such as calendar events, see Watches and reminders. For the other kinds of trigger (schedule and file), the run, the plan card and the API, see Triggers.
Create an event trigger
There are two ways.
- Ask in a Studio chat. Say what should start the run, for example “When someone opens a pull request on my repository, read it and tell me if it changes the docs.” The model proposes an event trigger. It shows a card with the sender, the event type, the matches, and what the run may do. Nothing exists until you confirm. When you confirm, the card shows the hook URL, the secret and a
curlexample once. - Use the form. On the Triggers page, create a trigger and choose When an event arrives. Fill in Sender (the
source), Event type, Only when (one field=value per line), the prompt and the model. After you create it, the page shows the secret once.
A chat in a messaging app cannot propose an event trigger. Create it in Studio.
Copy the secret into the sender at once. The server does not show it again. If you lose it, rotate it with Rotate secret on the trigger (or POST /api/chats/triggers/{id}/secret). The old secret stops working at the same moment.
The URL of the hook is the address of your server and the path /api/chats/triggers/{id}/hook.
Send an event
The hook is POST /api/chats/triggers/{id}/hook. It needs no login and no API key. The secret of the trigger is the credential. A sender can use one of three ways. The server picks the way from the headers, in this order.
In the examples, $URL is the hook URL and $SECRET is the secret of the trigger.
Signed call
Send a Unix timestamp in seconds and a signature. The signature is sha256= followed by the hex HMAC-SHA256 of the timestamp, a dot, and the exact body, with the secret as the key.
The timestamp must be within 5 minutes of the server clock. Use this way when you write the sender yourself.
The signature covers the timestamp and the body, and nothing else. The X-Webhook-Event header and the source query parameter are not signed: anyone who holds a signed call can change them and send it again within the 5 minutes. If the event type matters, put it in the signed body, in a text field type, and do not send X-Webhook-Event.
GitHub
GitHub signs the body with the secret and sends X-Hub-Signature-256. The server accepts that header as it is.
- Open the repository on GitHub, then Settings, then Webhooks, then Add webhook.
- In Payload URL, enter the hook URL of the trigger, for example
https://example.com/api/chats/triggers/<id>/hook. The server must be reachable from the internet over HTTPS. - Set Content type to
application/json. - In Secret, paste the secret of the trigger.
- Under Which events would you like to trigger this webhook?, choose the events you need, for example Pull requests. Do not choose Send me everything: every event that the trigger does not match is a call for nothing.
- Click Add webhook. GitHub sends a
ping. If the trigger has an event type such aspull_request, it answers202and starts no run. A trigger with an empty event type takes the ping as an event.
Create the trigger with the source github. The server reads the event type from the X-GitHub-Event header (pull_request, push, issues) and uses X-GitHub-Delivery as the key that removes repeats.
Bearer secret
For a script or a device that cannot sign, send the secret itself.
Send it only over HTTPS. Never put the secret in the URL (a query string ends up in logs and in browser history).
What the server answers
| Answer | Meaning |
|---|---|
202 with {"run": "<id>"} | The event started a run, or joined a run that waits, or was a repeat of an event that was already taken. |
202 with {"run": ""} | The event is valid but does not match the trigger. No run. |
404 | Refused. The body is the same for an unknown id, a trigger that is off, a wrong secret, a bad signature and a timestamp that is too old. The answer does not tell which. |
413 | The body is larger than 256 KiB (262144 bytes). |
503 with {"error":"unavailable"} | An internal failure. The event was not taken. Send it again. |
429 | More than 60 authenticated calls in one minute for this trigger. Retry-After is 60. |
How an event matches
A trigger has a source, an event type and up to 8 matches.
- Source is the name of the sender, for example
githuborwebhook. It is required. The server sets it togithubwhen the call has anX-GitHub-Eventheader, to thesourcequery parameter when there is one, and towebhookin all other cases. Letters are not case sensitive. - Event type is checked in the same way. An empty type takes any type. The server reads the type from
X-GitHub-Event, then fromX-Webhook-Event, then from a text fieldtypein the JSON body, and useseventwhen it finds none. - Matches are
field=valuechecks on the JSON body.fieldis a dot path, such asactionorpull_request.base.ref. A number in a path is an index in an array. Each check compares text: the value of the field must be equal tovalue. A body that is not JSON matches only a trigger with no matches.
A match is a fixed check, and it is cheap. For a rule that needs judgment, write the condition in the prompt, for example “Act only if the pull request changes a file under docs/.” A model that proposes the trigger can add one line like this as Act only if: .... Every run is told that when the condition of the prompt does not hold for the event, it must say so in one line and stop. Such a run uses a few tokens and the model is allowed to end it at once.
What a run may do
The run starts a chat with your prompt and the event data. The payload goes into the prompt as data between markers, cut to 8000 bytes, and the model is told it is not instructions.
An event run has only the tools that the trigger names, its acts, and only within what the agent of the trigger already holds. A trigger with no acts only reads and reports. It cannot write files or call add-ons. Name an act only when the run needs it.
Limits
| Limit | Value |
|---|---|
| Body of a call | 256 KiB. A larger one gets 413. |
| Calls for each trigger | 60 authenticated calls in a minute, counted for each server. A wrong secret is not counted. |
| Payload in a run | 8000 bytes of text. A longer payload is cut. |
| Runs in a day | 24 by default, at most 1000 (daily_cap). An event over the limit is recorded as a skipped run with the reason, and the sender still gets 202 with the id of that skipped run. The day is a day of the time zone of the trigger, or UTC when it has none. An event that joins a waiting run is not counted. |
| Gap between runs | 1 minute between two starts by default, at most 24 hours (min_gap_seconds). |
| Payloads in one waiting run | 8 |
Events during the gap
A run waits until the gap since the previous start has passed. Events that arrive while a run waits are not lost and do not make more runs. They join the waiting run: it keeps up to 8 payloads, oldest first, and says how many older ones were dropped. Each joined event shows as a skipped row in the run list, with the reason “merged into a waiting run”. The run then starts once and sees all of them.
An event that arrives while a run is going makes a new waiting run, unless a run of the trigger is already waiting: then it joins that one.
Repeats
The sender should give each event a stable key, because the server uses it to take one event only once, even if the sender retries. The key is the first of:
- for a signed call, the signature;
X-GitHub-Delivery;X-Webhook-Id;- the hash of the body and the current minute.
A repeat of an event with the same key answers 202 and makes no new run. This includes Redeliver in GitHub: it sends the same X-GitHub-Delivery, so it does nothing while the first run is still in the list of runs of the trigger. To run an event again, send a new one.
Security
- The secret is shown once, when you create the trigger or rotate the secret. Lists, reads and administrator views never show it. Store it in the secret store of the sender.
- Rotate the secret when it may have been seen. Rotation takes effect at once.
- A run with no acts can still read your files, and its answer goes to the delivery target. A pull request body, or any other text in a payload, can ask the run to read something and put it in its answer. The answer goes to the target of the trigger, and that can be a channel that other people read. Choose a private target, and name only the acts that the run needs.
- Treat the payload as untrusted text. Anyone who can make the sender send text, for example the author of a pull request or an issue, controls part of what the model reads. The prompt tells the model it is data, but no prompt makes this safe by itself. Name only the acts that the run needs, so that a bad payload cannot do much.
- A GitHub call and a bearer call can be replayed by anyone who captured one: the first has no timestamp, and the second is the secret itself. The repeat key stops a replay of the same delivery while the run that it made is kept in the list, but it is no protection against a sender that was never yours. A signed call cannot be replayed inside the 5 minute window, because its signature is the key, and it is refused after the window. Use a signed call when you control the sender.
- Do not put the secret in a URL. Use the headers.
- The hook checks the secret before it counts the call or reveals anything, and uses a constant-time check. An attacker who guesses ids learns nothing: every refusal is the same
404.