Revit API Context is the time Revit is ready to execute Revit API code in a safe place.
If your code tries to access some Revit API methods outside the Revit API Context probably you gonna receive an Exception: Invalid call to Revit API! Revit is currently not within an API context.
The most common way to place that your code is running outside the Revit API Context is when you create a modeless WPF, and usually is necessary to create an ExternalEvent that is a way to send a request to the Revit API to run that code in Revit API Context.
What is Revit API Context?
The video below shows some examples where Revit API is in context and outside context. And have the implementation to know if the code is InContext.
Subscribing to an event in the UIApplication or UIControllerApplication is only allowed when Revit API is in Context, this could be used to know if your code is inside or outside Revit API Context.
This implementation is used in the library ricaun.Revit.UI.Tasks to execute the code if is in context instead of waiting for the ExternalEvent to be executed by Revit API.
Now this InContext implementation the library gonna handle if the code gonna run right away or wait for the Revit API code to run in the ExternalEvent.