Incidents.CreateIncident
Open a manual incident from running code (create_incident): summary
says what’s wrong, description becomes its first comment;
requesterEmail is required with an API token.
Notifies. Opening an incident alerts the on-call team through the
channels the request turns on (call, sms, email, push,
criticalAlert) and the escalation policy (escalationPolicyId), after
teamWait seconds. Turn channels off for a quiet record.
Credential. These operations need an API token: Better Stack has no
narrower credential for them (no per-incident or per-page token, no
scopes). The host receives the ApiToken you pass — explicitly,
never the deployer’s own — under the name you give it (Redacted, a
secret on every host), plus <name>_TEAM_ID when you give a team.
The token can do everything it can do in the Uptime API, so use a
team-scoped Uptime API token (Settings → API tokens) rather than a
global one, and bind it only into hosts that need it.
Provide CreateIncidentHttp on the host’s implementation.
From a Cloud.Service
Section titled “From a Cloud.Service”Bind it with an explicit token
const IncidentsToken = BetterStack.apiTokenFromConfig("BETTERSTACK_INCIDENTS_TOKEN");
export default class Api extends BetterStack.Cloud.Service<Api>()( "Api", { server: Box, main: import.meta.url, port: 3000 }, Effect.gen(function* () { const openIncident = yield* BetterStack.Incidents.CreateIncident(IncidentsToken); return { fetch: Effect.gen(function* () { const incident = yield* openIncident({ summary: "Payments are failing", requesterEmail: "oncall@example.com", email: true, }); return yield* HttpServerResponse.json({ id: incident.id }); }).pipe(Effect.orDie), }; }).pipe(Effect.provide(BetterStack.Incidents.CreateIncidentHttp)),) {}On any Alchemy host
Section titled “On any Alchemy host”The token and ids are bound through RuntimeContext, so the same
yield* BetterStack.Incidents.CreateIncident(…) works in a Cloudflare Worker or a
Lambda Function, where the token becomes the host’s secret.