> For the complete documentation index, see [llms.txt](https://developer.fotokite.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.fotokite.com/code-examples/notifications.md).

# Notifications

To monitor the state of the system, especially during flight, it is strongly recommended to subscribe to system notifications via WebSockets.

For more details, see [#notifications](#notifications "mention") or the [GitHub repository](https://github.com/fotokite/fotokite-api/tree/main/example/).

### Subscribe notifications

The example demonstrates how to subscribe to live notifications to receive important system events, such as:

* Safety warnings
* System errors

```python
def notifications_telemetry(
    on_message_callback: Callable[[Notification], None],
    access_token: str,
    max_messages: int | None = None,
) -> None:
    """Subscribes to notifications telemetry.

    Args:
        on_message_callback: A callback function to handle incoming messages.
        access_token: The authentication token to use in the websocket connection.
        max_messages: The maximum number of messages to process. Defaults to None.
    """
    ws_url = f"{BASE_WEBSOCKET_API_URL}/notifications/subscribe"
    try:
        with connect(
            ws_url, additional_headers={"Authorization": f"Bearer {access_token}"}
        ) as websocket:
            logging.info("Connected to notifications telemetry")
            count = 0
            while True:
                message = websocket.recv()
                data = json.loads(message)
                on_message_callback(data)

                count += 1
                if max_messages is not None and count >= max_messages:
                    break
    except Exception as e:
        logging.error(f"Error in notifications telemetry: {e}")
```

An overview of important notifications can be found in the Fotokite Sigma User Manual under <https://manual.fotokite.com/failure-modes/messages-and-warnings>

### Get notification dictionary

A dictionary of all available notifications is provided in the following format:

* Code
* Severity
* Message (a human-readable interpretation of the notification for display in interfaces)

```python
def dictionary(access_token: str) -> dict[str, object]:
    """Fetches the notifications dictionary.

    Args:
        access_token: The authentication token to use in the request.

    Returns:
        A dictionary containing notification definitions with their codes and descriptions.
        If the request fails or an exception occurs, logs the error and returns an empty dictionary.

    Raises:
        requests.HTTPError: If the HTTP request fails with a status code other than 200.
        Exception: For any other exceptions encountered during the request.
    """
    try:
        headers = {"Authorization": f"Bearer {access_token}"}
        response = requests.get(
            f"{BASE_REST_API_URL}/notifications/dictionary", headers=headers
        )
        if response.status_code == 200:
            return cast(dict[str, object], response.json())
        else:
            response.raise_for_status()
    except Exception as e:
        logging.error(f"Error fetching notifications dictionary: {e}")

    return {}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developer.fotokite.com/code-examples/notifications.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
