AITWIN.ME

Docs

Create Twin Embed SDK

Embed the hosted Create AI Twin iframe so your users can build a private twin — face, voice, and optional brain — inside your product.

1

Generate an auth token

Your backend calls getAiTwinAuthToken with your Client-Id and Client-Secret. Return the authToken to your app and pass it as the token query param on the embed URL. Never expose your Client Secret in the browser in production.

Create credentials on the API Keys page, then generate a token below to try the live preview.

bash
curl -X POST "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwinAuthToken" \
  -H "Content-Type: application/json" \
  -H "Client-Id: YOUR_CLIENT_ID" \
  -H "Client-Secret: YOUR_64_CHAR_API_KEY" \
  -d '{"userId":"end-user-123","userName":"Jane Doe"}'

For testing only. In production, call getAiTwinAuthToken from your backend and pass the token to your iframe URL.

2

Embed the iframe

Host the Create AI Twin UI at /createAiTwin. End users pick a face, choose a voice, optionally add a brain, and save a private twin — no Firebase sign-in required.

html
<iframe
  src="https://aitwin.me/createAiTwin?token=YOUR_TOKEN&themeColor=EB7A1A"
  width="100%"
  height="640"
  style="border:0;"
  allow="microphone; camera"
></iframe>
Live preview
Generate a token in Step 1 to load the embed preview.

Add https://aitwin.me to your CSP frame-src when embedding on your own domain.

3

Handle the save response

When the user saves a twin, the iframe posts a message to your window. Listen for aitwin:create-twin:success and read the payload fields below. Validate event.origin matches https://aitwin.me before trusting the message.

FieldDescription
twinIdInternal twin identifier.
aiTwinUrlIdURL slug for the twin (use with <AiTwin id=… />).
faceIdSelected or uploaded face ID.
voiceIdSelected or cloned voice ID.
nameDisplay name entered by the user (optional).
isPrivateAlways true for embed-created twins.
knowledgeContextIdBrain / knowledge base ID when configured (optional).
javascript
window.addEventListener("message", (event) => {
  if (event.origin !== "https://aitwin.me") return;

  if (event.data?.type === "aitwin:create-twin:success") {
    const payload = event.data.payload;
    // { twinId, aiTwinUrlId, faceId, voiceId, name?, isPrivate, knowledgeContextId? }
  }

  if (event.data?.type === "aitwin:create-twin:error") {
    console.error(event.data.payload.message);
  }
});

Live result from preview above

Create a twin in the preview iframe to see the success payload here.