The PostMessage API enables secure cross-origin communication between your application and the embedded Corti Assistant. This method is suitable for iframe or WebView integrations requiring fine-grained control over the iframe lifecycle.Documentation Index
Fetch the complete documentation index at: https://docs.corti.ai/llms.txt
Use this file to discover all available pages before exploring further.
Web Component API is recommended. The Web Component API provides the same functionality with a simpler interface. PostMessage API remains fully supported but involves unnecessary complexity. It is not deprecated.
Web Component has full working examples. Complete, runnable examples are available for the Web Component integration method, which is the recommended approach for most integrations. PostMessage API examples demonstrating the lower-level protocol will be added to the repository in the future.
Overview
The PostMessage API uses the browser’spostMessage mechanism to enable secure communication between your application and the embedded Corti Assistant, even when they’re served from different origins. This makes it ideal for embedding Corti Assistant in iframes or WebViews.
Requirements
Before getting started, ensure you have:- Access to Corti Assistant: You’ll need credentials and access to one of the available regions
- HTTPS: The embedded Assistant must be loaded over HTTPS (required for microphone access)
- Microphone permissions: Your application must request and handle microphone permissions appropriately
- OAuth2 client: You’ll need an OAuth2 client configured for user-based authentication
- Modern browser or WebView: For web applications, use a modern browser. For native apps, use a modern WebView
Recommendations
- Validate message origins to ensure security
- Use specific target origins instead of
'*'when possible - Implement proper error handling for all API calls
- Handle authentication token refresh to maintain user sessions
- Request microphone permissions before initializing the embedded Assistant
Available regions
- US: https://assistant.us.corti.app
- EU: https://assistant.eu.corti.app
- EU MD: https://assistantmd.eu.corti.app (medical device compliant)
Features
- Secure cross-origin communication
- Works with any iframe or WebView implementation
- Fully asynchronous with request/response pattern
Quick start
Step 1: Set up authentication
Before using the PostMessage API, authenticate your users using OAuth2. See the Authentication Guide for complete setup instructions including Authorization Code Flow with PKCE (recommended), obtaining tokens, and handling token refresh.All Embedded Assistant integrations require user-based OAuth2 authentication. Client credentials and machine-to-machine flows are not supported.
- Handle token refresh to maintain sessions
- Never expose client secrets in client-side code
Step 2: Load the Embedded Assistant
Load the Corti Assistant in an iframe or WebView:Required iframe allow permissions
When you embed Corti Assistant in an iframe, you must delegate the browser permissions that the embedded app needs.
microphoneis required for recording and dictationdisplay-captureis required if you use virtual recording to capture audio from another tab, window, or screenclipboard-writeis recommended so users can copy generated content reliably across browsers
allow attribute on the iframe:
These examples omit
* intentionally. In an iframe allow attribute, each feature defaults to the iframe src origin, which is the safer default for Corti Assistant embeds. Use feature * only if you explicitly want to grant that permission to any origin the iframe might later navigate to.If you support virtual mode, include
display-capture so the embedded Assistant can request browser-managed capture of remote audio streams.Message format
All messages sent to the embedded app follow this structure:Message properties
type: Always'CORTI_EMBEDDED'version: API version (currently'v1')action: The method to invoke (see API Reference for all methods)requestId: Optional unique identifier for tracking responsespayload: Optional data specific to the action
Same API as Web Component
The PostMessage API provides access to the same methods documented in the API Reference -auth, configure, createInteraction, etc. - with identical parameters and behavior.
Key difference: Instead of direct method calls that return Promises, you communicate through messages:
- Send a message with
actionfield matching the method name - Receive the response asynchronously via a separate
CORTI_EMBEDDED_RESPONSEmessage
auth:
Response handling
Responses from the embedded app are sent viapostMessage and can be identified by checking the message type:
Events
Corti Assistant dispatches events to notify your application of state changes and important updates. When using the PostMessage API, these events are wrapped in theCORTI_EMBEDDED_EVENT message type.
Event format translation
Core events documented in the Events Reference are wrapped for postMessage delivery: Core Event Structure:Listening for events
Set up a message listener to receive events from the embedded Assistant:Listening for Events
Available events
For a complete list of events and their payload structures, see the Events Overview. Common events include:recording.started- Recording has startedrecording.paused- Recording has pauseddocument.generated- Document has been generateddocument.updated- Document has been editeddocument.synced- Document synced to external systemerror.triggered- An error occurred
Legacy events
The embedded Assistant also dispatches legacy events using camelCase names (e.g.,
recordingStarted, documentGenerated). These are deprecated and will be removed in a future version.Error handling
Always handle errors when making requests:Error Handling
Security considerations
When usingpostMessage, always:
- Validate message origin: Check
event.originto ensure messages come from trusted sources - Use specific target origins: Replace
'*'with the specific origin when possible - Sanitize data: Never trust data from postMessage without validation
Security Best Practices
Next steps
- Review the OAuth Authentication Guide to set up user authentication
- See the API Reference for all available methods and their parameters
- Learn about events that the embedded app can send
- Check out the Window API for same-origin integrations
Please contact us for help or questions.