# Getting started with AI SRE API

## How AI SRE API works

Our API follows the [JSON:API](https://jsonapi.org/) specification.

API requests to the AI SRE API are authorized using the [Bearer Authentication standard](https://swagger.io/docs/specification/authentication/bearer-authentication/): add an `Authorization: Bearer $TOKEN` header to your requests. The AI SRE API uses the same tokens as the Telemetry API.

Chats run asynchronously. [Create a chat](https://betterstack.com/docs/ai-sre/api/chats/create/) or [reply to one](https://betterstack.com/docs/ai-sre/api/chats/reply/) and the request returns as soon as your message is saved, with the chat in the `processing` status. Then:

1. Poll the [chat status](https://betterstack.com/docs/ai-sre/api/chats/status/) until it leaves `processing`.
2. When the status is `awaiting_confirmation`, [approve or deny](https://betterstack.com/docs/ai-sre/api/chats/resolve-confirmation/) each pending confirmation. The agent then continues and the status returns to `processing`.
3. When the status is `idle`, [get the chat](https://betterstack.com/docs/ai-sre/api/chats/get/) and read the last `ai` message. Its `text` carries the answer as markdown and its `artifacts` carry any reports.

Write requests to the AI SRE API are limited to 100 per minute per token.

## Get a global API token

A global API token is a token **valid across all your teams**, for managing anything within Better Stack.

- Go to [Better Stack → API tokens](https://betterstack.com/settings/global-api-tokens ";_blank")
- Copy an existing token or create a new one in the **Global API tokens** section.

![Global API Token](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/267e3eb0-5de4-45dd-c830-7ddad6cdc900/lg2x =3288x1214)

## Get a Telemetry API token

A Telemetry API token is a **team-scoped token** for managing your Telemetry resources, including AI SRE chats. You can get a separate API token for each of your teams.

- Go to [Better Stack → API tokens → Team-based tokens](https://betterstack.com/settings/api-tokens/0 ";_blank")
- Select your team.
- Copy an existing token or create a new one in the **Telemetry API tokens** section.

![Telemetry API Token](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/1db07729-033d-4530-78e4-860da8cd5e00/lg1x =1111x343)
