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

# BCI

You can use the Cortex API to develop a brain–computer interface (BCI), using facial expressions, mental commands, or both.

{% hint style="info" %}
Before you start programming your own BCI, it is strongly recommended that you use [EmotivBCI](https://www.emotiv.com/emotiv-bci/) to get familiar with the main BCI features of Cortex.\
You should also check out the [EmotivBCI Node-RED Toolbox](https://emotiv.gitbook.io/emotivbci-node-red-toolbox/).
{% endhint %}

{% hint style="info" %}
To use the BCI features with an EPOC Flex headset, you must use a special EEG mapping. Please see [Data Subscription](/cortex-api/data-subscription.md#special-eeg-sensor-mapping-for-epoc-flex) for details.
{% endhint %}

To get the results of the facial expression detection and the mental command detection, you must [subscribe](/cortex-api/data-subscription/subscribe.md) to the data streams "fac" and "com" respectively.

To use the mental command detection, you must [load](/cortex-api/bci/setupprofile.md) a training profile that contains training data for at least one action. For the facial expression detection, the training is optional.

## Profile

A profile is a persistent object that stores training data for the facial expression and mental command detections. A profile belongs to a user and is synchronized to the EMOTIV cloud.

You can use [queryProfile](/cortex-api/bci/queryprofile.md) to list the profiles of the current user. Use [setupProfile](/cortex-api/bci/setupprofile.md) to manage the profiles, and also to load or unload a profile for a headset. You can use [training](/cortex-api/bci/training.md) to add training data to a profile.

Before v3.6.5, a profile can be loaded for both Epoc/Flex and Insight. Since v3.6.5, a profile can only be loaded for Epoc/Flex or Insight since their EEG channels are different. If you upgrade from version before 3.6.5, the existing profiles will become readonly. See [Readonly training profile.](/cortex-api/bci/readonly-profile.md)

## Training workflow

The training works that same for the mental command detection and the facial expression detection. However, they don't use the same actions, events or controls. So you should call [getDetectionInfo](/cortex-api/bci/getdetectioninfo.md) to know what actions, controls and events you can use for each detection.

Before you start a training, you must [subscribe](/cortex-api/data-subscription/subscribe.md) to the data stream "sys" to receive the training events from Cortex. Then you can follow these steps:

1. Start the training by calling [training](/cortex-api/bci/training.md) with the action you want to train and the **control "start".**
2. On the "sys" stream, you receive the **event "started".**
3. After a few seconds, you receive one of these two events:
   1. **Event "succeeded",** the training is a success. Now you must accept it or reject it.
   2. **Event "failed",** the data collected during the training is of poor quality, you must start over from the beginning.&#x20;
4. Call [training](/cortex-api/bci/training.md) with the **control "accept"** to add the training to the profile. Or you can use the **control "reject"** to reject this training, and then you must start over from the beginning.
5. Cortex sends the **event "completed"** to confirm that the training was successfully completed.
6. You should [save the profile](/cortex-api/bci/setupprofile.md) to persist this training. If you unload the profile without saving, then the training is lost.

After step 2, but before step 3, you can send the **control "reset"** to cancel the training.

The following chart illustrates the flow of BCI training with corresponding request for each step:

![](/files/-M8hWfVzqsqzroQcdEpj)

## Getting live actions

The following chart illustrates the streaming of Mental Commands data in live:

![](/files/-M8hWoaT1IvbQKDH_o8d)


---

# 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://emotiv.gitbook.io/cortex-api/bci.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.
