Unity SDK (beta)

How to add Integrava chat to a Unity project. This package is a beta. The website widget and the server API are separate.

Last updated November 11, 2026

What this is

This is the customer guide for the Unity SDK (beta). It is a Unity Package Manager package named ai.integrava.unity, version 0.1.2. The player calls the same public chat HTTP API as the website widget. There is no websocket.

Integrava has three ways to reach the assistant. Use this package for a Unity project. Use the website widget for a site. Use the server API on your backend to mint identify tokens, send events, and receive webhooks. The last section says which one to pick.

There is no native iOS package, no native Android package, and no React Native or Flutter package. A Unity player that you build for iOS or Android can include this C# package. Integrava does not ship or sign that player.

This beta has no attachments, no offline queue, no push notifications, and no localized UI strings. Replies use the same long poll as the website widget, up to 15 seconds. Chat uses your AI key. Integrava's per-conversation fee is unchanged. This package does not add a separate AI meter.

1. Prerequisites

  • Unity 2021.3 or newer.
  • An Integrava workspace you can sign in to.
  • A widget from Embed Assistant, and its public widget token. That token is safe in the Unity project.
  • A server API key (integrava_sk_…) from Integrations → API keys. Store it only as INTEGRAVA_SECRET_KEY on your server. Do not put it in the Unity project, a scene, or a build.
  • Your workspace slug. It is the slug in your public Help Center URL. Help article calls need it. Chat does not.
  • A backend route that already knows which player is signed in. The sample mint server is only for local tests.

2. Install the package

In Unity, open Package Manager and choose Add package from git URL:

https://github.com/customersuccesspoint/integrava-unity-sdk.git#v0.1.2

package.json is at the root of that repository. The #v0.1.2 tag is this beta. Pin that tag when you ship. The package name is ai.integrava.unity. An OpenUPM listing is a separate step. There is no release tarball.

To try the included UI, open Package Manager, select Integrava Unity SDK (beta), and import Chat sample. Unity copies it into your project. Open the IntegravaChat scene from that copy. In the package the scene is Samples~/Chat/IntegravaChat.

3. Mint identify tokens on your server

The Unity project must not call Integrava with the server key. After your own login has accepted the player, your server calls POST https://api.integrava.ai/api/v1/identify-token with Authorization: Bearer and the key from INTEGRAVA_SECRET_KEY.

The JSON body needs externalUserId, a stable id from your account system, up to 256 characters. Optional fields are displayLabel, traits, and widgetId. Leave widgetId out unless you want the token to work on only that widget. A token whose widget id does not match the widget in the game is rejected.

A success response is identifyToken, expiresAt, and expiresInSeconds (900). Return only identifyToken to the game. Tokens last 15 minutes and can be reused until they expire. The client asks your callback again when Integrava says the token is missing or expired.

Minimal Node example. Use the player id from your login, not an id the game is allowed to invent:

const secret = process.env.INTEGRAVA_SECRET_KEY;
const upstream = await fetch("https://api.integrava.ai/api/v1/identify-token", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${secret}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({ externalUserId: playerId })
});
const data = await upstream.json();
// Send only data.identifyToken to the game.

Optional INTEGRAVA_API_BASE replaces https://api.integrava.ai when you point at another API host.

The Chat sample includes Samples~/Chat/backend/mint-identify-token.mjs for a local test. It reads INTEGRAVA_SECRET_KEY, listens only on 127.0.0.1, and defaults to port 8787. It trusts externalUserId from the request body, so do not expose that process on the internet. A production route must mint for the player your login already authenticated.

INTEGRAVA_SECRET_KEY=integrava_sk_... node mint-identify-token.mjs

Optional INTEGRAVA_MINT_PASSWORD must match the sample's mint password field. The sample sends it as X-Integrava-Mint-Password. That password is yours. It is not the Integrava secret key. Optional PORT changes the listen port.

4. Configure the client

Reference Integrava.Core and Integrava.Runtime. Create the client on the Unity main thread.UnityWebRequest and PlayerPrefs are main-thread APIs. A call from another thread throws Integrava Unity calls must run on the main thread.

var client = new IntegravaClient(new IntegravaClientOptions
{
    BaseUrl = "https://api.integrava.ai",
    WidgetToken = publicWidgetToken,
    WorkspaceSlug = "your-workspace-slug",
    IdentifyTokenProvider = ProvideIdentifyToken,
    SessionStore = new IntegravaPlayerPrefsSessionStore(),
    Transport = new IntegravaUnityTransport()
});
  • BaseUrl is the API host, with no path. A trailing slash is ignored.
  • WidgetToken is the public widget token. The constructor rejects a value that contains integrava_sk_.
  • WorkspaceSlug is required for Help Center reads. Chat works without it.
  • IdentifyTokenProvider is Func<bool, CancellationToken, Task<string>>. The bool is forceRefresh. When it is true, discard any cached token and mint again. Return the identify token only.
  • IntegravaPlayerPrefsSessionStore stores the conversation id. The key is a hash of the API host and the widget token, so staging and production do not share a session, and the raw token is not the key.
  • IntegravaUnityTransport sends the identify token as X-Integrava-Identify-Token. Chat also puts identifyToken in the JSON body. The body value wins if both are present. The token is never a query parameter.

The Chat sample sets the same values on the IntegravaChat object: base URL, widget token, workspace slug, identify mint URL, external user id, and an optional mint password. Leave the editor-only identify token empty in player builds. That field is a token you already minted, for Editor tests when you are not running the mint server.

5. Open chat

Call these from the main thread, with a cancellation token you cancel when the scene unloads.

var config = await client.GetWidgetConfigAsync(cancellationToken);
var sent = await client.SendMessageAsync("Hello", cancellationToken);
var history = await client.PollHistoryAsync(12000, knownCount, lastMessageId, cancellationToken);
var articles = await client.ListArticlesAsync(cancellationToken);
var article = await client.GetArticleAsync(pageSlug, cancellationToken);
  • GetWidgetConfigAsync returns the assistant name and the AI notice. Show AiDisclosureText when AiDisclosureEnabled is true. The sample does this.
  • SendMessageAsync posts to /api/public/chat. An empty message is rejected locally and does not call the API. It does not send escalateToAgent. The reply text is Reply. A busy widget can return HTTP 200 with ChatLimited and that reply, and an empty message list. A blocked sender returns HTTP 200 with ChatUnavailable. WaitingForAgent is true when a person has the conversation. The sample keeps the visitor line, shows Reply when the message list is empty, and does not add its own waiting message. The server session id is saved for the next send.
  • PollHistoryAsync long-polls /api/public/chat/history. waitMs is clamped to 0 through 15000. The sample waits 12000. Pass the previous message count and last message id. If there is no stored session yet, the method returns an empty history and does not call the API. NeedsReplyRetry means the last stored message is still waiting for a bot reply. Call RetryAssistantReplyAsync, which posts to /api/public/chat/retry. The sample does that once while a retry is not already running. ChatUnavailable stops the sample poll. A new sessionId on history replaces the stored session.
  • ListArticlesAsync and GetArticleAsync read published Help Center articles. They do not send an identify token. They do not include the Help Center contact form. BodyText is the article HTML with tags removed.
  • ClearSession() deletes the stored conversation id for this host and widget token.

The sample builds a uGUI chat at runtime. Colors, font, and font size on the sample component are public so you can restyle them. The sample looks up Unity's built-in fonts itself. You do not need to edit a font line. You can ignore the sample UI and call IntegravaClient from your own screen.

You do not need to change Active Input Handling. The sample works when that setting is Input Manager (Old), Input System Package, or Both. A new Unity 6 project usually uses the Input System. The sample uses that when the Input System package is installed, and the older input module otherwise.

Network failures, HTTP 429, 409, 502, and 503 are retried up to 4 attempts, with delays of 500, 1000, 2000, and 4000 milliseconds, capped at 8000. HTTP 500 is not retried. A chat retry reuses the same clientMessageId, so a stored reply is replayed instead of a second model turn. IDENTIFY_INVALID and IDENTIFY_REQUIRED refresh the token once, then fail.

If you write your own UI, cancel the history poll when the player backgrounds the app, and start it again when they return. The Chat sample does that in OnApplicationPause. The core client does not watch the app lifecycle for you. Unloading the scene should cancel requests that are still in flight.

6. Identify players

The Unity package does not take the server key, and it does not call /api/v1/identify-token itself. Your callback asks your server, and your server mints the token as in step 3.

Standalone, iOS, and Android players send no browser Origin or Referer. Widget config, chat, and history then require a valid identify token for that workspace. The token's player id must match the conversation. An anonymous website session cannot be read or continued by the game. A mismatch returns IDENTIFY_MISMATCH, and the client clears the stored session id.

Cache the token until shortly before expiresInSeconds. When forceRefresh is true, mint a new one. On logout, stop returning the old token and call ClearSession().

The sample posts {"externalUserId":"..."} to the mint URL you set, reads identifyToken, and refreshes about a minute before expiry. If the mint URL is empty and the editor identify token is set, Play mode uses that token instead.

7. Send events

The Unity package has no event method. Send events from your server, with the same INTEGRAVA_SECRET_KEY. The game can tell your server what happened. Your server then calls POST /api/v1/customers/events.

await fetch("https://api.integrava.ai/api/v1/customers/events", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.INTEGRAVA_SECRET_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    externalUserId: playerId,
    event: "task_completed",
    properties: { step: 3 }
  })
});

externalUserId is required. event is a string from 1 to 128 characters. properties is an optional object. A success body is {"ok":true}. If you configured an HTTPS webhook, Integrava posts customer.event. Verify X-Integrava-Signature with your webhook secret.

Identifying a player for chat is the identify token in step 3, not this events route. POST /api/v1/customers/identify updates the profile from your server without opening chat. It is also server-only.

8. Test in the Unity Editor

  1. Deploy the API that includes this Unity access before you point a build at production.
  2. On your computer, run the sample mint server with INTEGRAVA_SECRET_KEY set. It listens at http://127.0.0.1:8787/identify-token.
  3. In the IntegravaChat scene, set the API base URL, the public widget token, the workspace slug, the mint URL above, and an external user id such as player-1. Leave the editor identify token empty.
  4. Press Play. The AI notice comes from the widget config. Send a message. Open Help and confirm published articles for that workspace slug.
  5. Put a string that contains integrava_sk_ in the widget token field and press Play again. The sample refuses to start.

The Editor pause button does not call OnApplicationPause. An unfocused Game view does not stop the sample poll. Background and resume is a device check.

9. Test on an Android device

  1. Run the mint route on a host the phone can reach. 127.0.0.1 on the phone is the phone itself, not your computer.
  2. Set that mint URL on the sample. Keep the server key on the server.
  3. Build an APK or AAB with your keystore. Integrava does not code-sign the package.
  4. Sideload the APK, or install the build from your store track. Send a chat message.
  5. Background the app, then open it again. The sample stops the long poll in the background and starts it when the player returns.

iOS uses the same C# package. Export on a Mac and sign with your Apple Developer account. iOS blocks plain HTTP unless the player allows that host.

10. WebGL

WebGL runs in a browser. The page sends Origin or Referer, so it stays on the widget allowlist. It does not get the native path. Add the site host in Embed Assistant before you publish. An empty domain list blocks every browser origin. A valid identify token does not bypass a disallowed origin.

The Unity client still sends an identify token. Keep the mint URL reachable from that page. A page opened as a local file is not an allowed website.

Cloudflare Turnstile stays on browser requests, including WebGL. This client cannot complete that challenge. Leave Turnstile off on the widget the game uses. You can keep Turnstile on a different widget that only the website uses.

Per-IP and per-token rate limits still apply on every path, including WebGL and native players.

11. Troubleshooting

  • Refusing to start. A sample field contains integrava_sk_. Move the key to INTEGRAVA_SECRET_KEY on the server.
  • Identify callback returned a server secret key. The callback returned the server key instead of identifyToken.
  • Identify token callback failed. Your callback threw. The client hides the inner message so a secret in that exception is not shown.
  • IdentifyRequired. The player sent no Origin and no Referer, and no token. In the sample, set the mint URL or an editor identify token. On the server this code is IDENTIFY_REQUIRED.
  • IdentifyInvalid. The token is expired, signed for another workspace, has a widget id that does not match, or the signature is wrong. The client mints once more, then surfaces IDENTIFY_INVALID.
  • IdentifyMismatch. The stored conversation belongs to a different player, or it is an anonymous website session. The client clears that session id. Send again to start a conversation for this player.
  • OriginRejected. The request had an Origin or Referer that is not on the widget allowlist. The error text is Origin not allowed, code ORIGIN_NOT_ALLOWED. This is the WebGL case. Editor and device players normally omit those headers.
  • Identify mint failed. The phone or Editor could not reach your mint URL, or the mint password did not match. On a device, do not use 127.0.0.1 unless the mint server is on that device.
  • Network request failed. The API host is wrong, or the device cannot reach it. iOS may be blocking HTTP.
  • RateLimited. Chat sends default to 600 requests an hour for an IP address and 3000 an hour for a widget token. The client retries HTTP 429. Those defaults can be changed on the server. Server API keys have a separate limit of 120 requests a minute. A widget can also cap new chats per IP address. That cap is HTTP 200 with ChatLimited, not HTTP 429.
  • HTTP 500. Not retried. HTTP 409, 502, and 503 are retried.
  • Integrava Unity calls must run on the main thread. Create the client, send, poll, and read PlayerPrefs from the main thread.
  • Workspace slug is required. Help list and article reads need the slug. Chat does not.
  • Widget not found or disabled. The public token is wrong, or the widget is off.
  • HTTP 402. The workspace conversation or deflection limit was reached. That is the same billing path as the website widget.
  • Turnstile errors on WebGL. Turnstile is enabled on this widget. Turn it off for the game widget. Native players are not asked for Turnstile.

12. Website widget or server API instead

Use the website widget for a site or web app. Create the widget in Embed Assistant, add allowed domains, and paste widget.js. After the visitor signs in with you, your server mints an identify token and the page calls IntegravaAI.identify with that token. Turnstile, when you enable it, runs only in this browser widget. A request that still has Origin or Referer always stays on the allowlist, even with a valid identify token.

Use the server API from your backend for any app, including apps that are not Unity. Mint tokens at /api/v1/identify-token, update a profile at /api/v1/customers/identify, and send events at /api/v1/customers/events. Keep the server key on the server. Optional webhooks notify your server. Signed-in setup for keys is under Integrations, API keys. Webhooks are the next tab.

There is no package for a native iOS app, a native Android app, React Native, or Flutter. A WebView that loads the website widget is a browser: add that host to allowed domains. A custom client that omits Origin and Referer must send a valid identify token, in the JSON body as identifyToken or in the X-Integrava-Identify-Token header, and may continue only a conversation owned by that same player.

Public Help Center reads, GET /api/public/help/{workspaceSlug} and GET /api/public/help/{workspaceSlug}/articles/{pageSlug}, do not need an identify token.