This is a Frontend SDK method. It runs in the browser — import it in your React/Next.js component, not on the server.
Install
How it works
Two steps only:- Call your backend to get a
token - Call
AssessmentPortal.open({ token, apiKey })— the iframe opens and the candidate takes the test
onDone callback. The onDone / onClose callbacks are only for updating your UI (e.g. showing a toast message).
Signature
Parameters
string
required
The session token from your backend. This is
response?.data?.token from your assessmentApi.createSession() call.Never hardcode this — always fetch it fresh from your backend first.string
Your SmartAI public API key. This tells the portal which environment to load (live or test).Where to get it: Same key you use on the backend as Use it in code:
ASSESSMENT_API_KEY. The difference is how you expose it:Setup — add this to your frontend
.env.local:function
(result: { assessmentId: string }) => voidCalled when the candidate successfully submits the assessment. This is your signal to show a success message to the recruiter.function
() => voidCalled when the candidate closes the portal without submitting. The assessment is not complete — no result will appear in the webhook queue.function
(error: Error) => voidCalled when something goes wrong — invalid token, network failure, etc.number
default:"9999"
CSS z-index of the overlay. Increase if your app has elements that appear on top of the iframe (sidebars, modals with very high z-index).
Why await import(...) instead of a regular import?
window and document, which don’t exist during Next.js server-side rendering. The dynamic import tells Next.js to load this package only when the code actually runs in the browser.

