Skip to main content
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:
  1. Call your backend to get a token
  2. Call AssessmentPortal.open({ token, apiKey }) — the iframe opens and the candidate takes the test
Results are collected on your server by polling — not via the 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 ASSESSMENT_API_KEY. The difference is how you expose it:Setup — add this to your frontend .env.local:
Use it in code:
Never add ASSESSMENT_SECRET_KEY to a NEXT_PUBLIC_ variable. The secret key signs requests and must stay on the server only. Only the API key (not the secret) goes in the frontend env.
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?

The frontend SDK uses 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.

TypeScript type declaration

If your IDE shows “cannot find module” or type errors:

Common mistakes