Curae Connect
Embed the Connect ceremony so a user links their health system — with the API key kept server-side and the LIMITED→ACTIVE graduation handled for you.
Curae Connect
Curae Connect is the hosted ceremony where a user authorizes access to a health system (EHR). It runs in the user's browser via a popup; your API key never enters the browser.
What the person sees
- "Your app uses Curae Connect to connect your health records" — your app, named by the legal entity Curae verified in its review ("Your app by Your Company Inc."), what Curae promises the person, and Curae's documents to accept.
- Find your health system — the directory search. A valid
brandIdcan select an institution on the silent limited-account path; a stale or invalid hint falls back to the picker, and other paths ignore it. - What your app will receive — one row per thing your scope asks for, a switch for each sensitive category it asks for, every one off, and the authorization the person signs by tapping Allow. Don't Allow shares nothing.
- Sign in at the health system — on its own sign-in page (SMART on FHIR).
- You're connected — the popup closes and your app is told.
A sensitive category is granted only when the person turns it on, so an
authorized connection's scope can be narrower than the scope you asked for.
Read the connection's scope before relying on one.
Recommended integration
The SDK provides account-lifecycle handlers and an account provider. Mount them alongside your connection-create proxy (described below).
1. Mount the server proxy once (e.g. app/api/curaeai/[...curaeai]/route.ts):
import { createCuraeAIRouteHandlers } from '@curaeai/platform-sdk/server';
import { auth } from '@/lib/auth';
export const { GET, POST } = createCuraeAIRouteHandlers({
apiKey: process.env.CURAEAI_API_KEY!,
baseUrl: process.env.CURAEAI_BASE_URL,
resolveAppUserId: async () => (await auth())?.user?.id ?? null,
});2. Wrap your app once (inside your auth gate):
import { CuraeAIAccountProvider } from '@curaeai/platform-sdk/react';
<CuraeAIAccountProvider appUserId={session.user.id}>
{children}
</CuraeAIAccountProvider>;3. Gate on isReady:
import { useCuraeAIAccount } from '@curaeai/platform-sdk/react';
function Feature() {
const { isReady } = useCuraeAIAccount();
if (!isReady) return null; // provider renders the upgrade UI automatically
// Account is ready; requests still require connection authorization.
}isReady describes account lifecycle; your server must still check the
connection authorization for each resource request. The provider detects a LIMITED account, renders the upgrade prompt at the
right moment, sends the user through the Curae-hosted graduation, and
reconciles state on return — so the LIMITED → ACTIVE graduation needs
no code in your app.
The widget directly
If you're not using the provider, render the button and host a proxy
yourself. The widget POSTs an empty body to connectEndpoint. Your proxy
must authenticate the caller, derive appUserId from your session, supply
the approved SMART scope and any registered return URL, and call
client.createSdkConnection with an idempotency key. Return its data
object ({ connection, nextAction }) verbatim. Forwarding the empty widget
body to the platform fails validation: appUserId and scope are required.
createCuraeAIRouteHandlers serves only /session, /initiate and
/graduate under its mount path; it does not provide /connections.
Its return URLs, including defaults, must be registered for your app exactly.
Protect your own mutation proxies using your authentication and CSRF controls.
import { CuraeConnect } from '@curaeai/platform-sdk/react';
<CuraeConnect
connectEndpoint="/api/curaeai/connections"
onSuccess={({ connection }) => {
// `connection` is the row your proxy returned when the ceremony began:
// AUTHORIZED if no popup was needed, otherwise PENDING as created. The
// platform has authorized it by now — your backend learns that from the
// `connection.authorized` webhook or a GET on `connection.id`.
}}
onConflict={({ connection }) => {
// The chart appears to belong to another Curae account. The person must
// verify their identity before the connection can complete; it stays
// PENDING. Show "we're verifying it's you" — this is not a failure.
}}
onRefused={({ connection, reason }) => {
// Curae declined to complete the link under one of its own rules. Nothing
// failed and no records were shared; the connection stays PENDING.
// `reason` says what to tell the person — see below.
}}
onExit={() => {
/* user dismissed the popup */
}}
onError={(error) => {
/* the proxy call or the popup launch failed */
}}
/>;A framework-agnostic web component (<curae-connect-button>) is available
from @curaeai/platform-sdk/connect for non-React apps; it dispatches the
same outcomes as curae-connect:success / :conflict / :refused /
:exit / :error events.
Where the link opens
The widget opens nextAction.url in a top-level popup. A native app opens it
in the system browser: ASWebAuthenticationSession on iOS, Custom Tabs on
Android. An embedded web view is not supported. The link works once: the
first browser to open it holds the session, and every later step, the
hospital sign-in and Manage sharing included, runs in that browser. A second
opening is refused as expired; start again with a new connection.
When the link is refused
A refusal is the platform applying a rule, not a fault. The reason is one of
the closed SDK_LIMITED_CONSOLIDATION_* codes (CuraeConnectRefusalReason);
the ones a connect ceremony produces, and what to do:
reason | What happened | What to do |
|---|---|---|
SDK_LIMITED_CONSOLIDATION_USER_NOT_ELIGIBLE | One of the two accounts the chart would have joined is not in a state that admits it right now — most often the person completed another link in the last 24 hours and that merge can still be undone. The per-user detail is deliberately not disclosed. | Tell the person to try again later. |
SDK_LIMITED_CONSOLIDATION_STATE_CONFLICT, SDK_LIMITED_CONSOLIDATION_LINEAGE_REVERSIBLE | The accounts changed under the ceremony, or an earlier link of theirs can still be undone. | Try again later. |
SDK_LIMITED_CONSOLIDATION_CHART_CUSTODY_CONFLICT | The receiving account already held a live link to this chart when the merge tried to move it — a link created moments earlier, or a platform defect. The whole merge was aborted before anything moved, so the person is NOT linked. | Start the link once more: a retry sets that chart aside and completes the merge. If it is refused again, report it to Curae with the connection.id. |
SDK_LIMITED_CONSOLIDATION_PROOF_MISMATCH | The hospital proof the merge requires did not match. | The person can start the link again; do not retry automatically. |
SDK_LIMITED_CONSOLIDATION_TENANT_WRONG_KIND, SDK_LIMITED_CONSOLIDATION_INPUT_INVALID, SDK_LIMITED_CONSOLIDATION_SOURCE_NOT_APP_SCOPED, SDK_LIMITED_CONSOLIDATION_LINEAGE_STATE, SDK_LIMITED_CONSOLIDATION_NOOP | An integration or data-shape problem the client cannot fix. | Report it to Curae with the connection.id. |
The remaining members of the vocabulary (…_NOT_FOUND, …_ALREADY_REVERSED,
…_NOT_COMPLETED, …_WINDOW_EXPIRED, …_SNAPSHOT_INVALID) are raised only
by the merge-undo API and never by a connect ceremony; keep a default branch
when switching on reason.
What you get back
A connection has a lifecycle the platform keeps you in sync with via
webhooks: connection.authorized, connection.reconnected,
connection.expired, connection.action_required, connection.revoked.
Cache the connectionId; use it for record reads and exports.
A connection the person did not finish stays PENDING, and creating another
for the same user is refused 409. When the person signed in at their
hospital and only Curae's approval was left, :reconnect completes it: 202
with the connection AUTHORIZED and nextAction null. Any other PENDING
connection refuses :reconnect with 409; end it with :revoke
(client.revokeSdkConnection), then create a new one.
Let people manage their sharing
A user whose Curae account was made through your app has no Curae sign-in, so your app is their way to stop sharing. The Developer Agreement requires two things of every app with a connection:
- Your own control that stops the sharing. When the user uses it, revoke
the connection at that moment (
client.revokeSdkConnection,POST /api/sdk/v1/connections/{connectionId}:revoke). Make it easy to find, free, and no harder to use than connecting was. - Open Curae Connect when the user asks to manage their sharing. From
your server, initiate a session for the user with
manageSharing: trueand send them to the link you get back:
const result = await client.initiateCuraeConnect(
{ appUserId, manageSharing: true },
{ idempotencyKey: randomUUID() },
);
if (result.data.handoffUrl !== null) {
// Curae Connect's Manage sharing screen. Open it as returned: the token
// rides the URL fragment.
redirect(result.data.handoffUrl);
}On Manage sharing the user sees what they share with your app and until when, gets a copy of each authorization they signed, stops sharing, or deletes their Curae Connect account. The link works for a few minutes and only for that user and your app.
handoffUrl is null when there is nothing to open: the user has no Curae
account yet, or has a full Curae account and manages sharing in Curae under
Consents.
Whichever way sharing stops, your app hears it the same way: a
connection.revoked webhook for each connection that ended.
Delete what you received through it within 24 hours.
Next
- Webhooks — react to connection + data events.
- API reference — the
/api/sdk/v1/connectionscontract.