> For the complete documentation index, see [llms.txt](https://bonspiel-games.gitbook.io/cortex-unity-plugin/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bonspiel-games.gitbook.io/cortex-unity-plugin/overview-of-the-cortex-api-flow.md).

# Overview of the Cortex API flow

## Basic Flow

1. Import the CortexPlugin namespace
2. Call [Cortex.Start](/cortex-unity-plugin/cortex/methods.md#start) with your cortex app's client id and secret
3. Subscribe to [Cortex.HeadsetQueryResult](/cortex-unity-plugin/cortex/events.md#headset-query-result) to periodically receive a list of available headsets
4. [Connect to a headset](/cortex-unity-plugin/cortex/methods.md#connect-device) or [start a session](/cortex-unity-plugin/cortex/methods.md#start-session) if the device is already connected
5. [Subscribe to data streams](/cortex-unity-plugin/cortex/data-subscription.md)

The underlying Cortex API runs on an asynchronous request response paradigm standard to web communication. This Package adapts this approach slightly to provide responses as subscribable events, materially disconnected from the requests that might have initiated them.

This approach is intended primarily to simplify the use of the device information and mental command data streams by allowing you to subscribe to them anywhere using the headset id once a session has been started.

Practically, this leads to one primary workflow. Scripts subscribe to relevant events when initialized or enabled, unsubscribing when destroyed or disabled. Requests are made when needed, with care taken outside of the plugin through subscription or checks that only relevant events are being acted upon. This is Demonstrated in the Headset Manager sample class:

{% embed url="<https://github.com/cm-nielsen/CortexPlugin/blob/master/Samples~/SimpleCortexSample/Scripts/HeadsetManager.cs>" %}

<figure><img src="/files/wzTeQvIv7dE4pFAqHewV" alt=""><figcaption></figcaption></figure>
