Skip to content
Browse articles
Guides

Identity and security

How agent44 knows who a user is, what the public key allows, and how to keep users' conversations safe.

Agent44Updated 8 min read

On this page

In one minute#

Your app tells agent44 who its user is by sending your own user id with each request. Your public key ships inside your app or web page, so anyone can find it. Without identity verification, agent44 trusts the id as sent, which means:

Anyone who has your public key and a user's id can act as that user. They can read and send that user's messages, change what identify saved about them and register a device that gets their push notifications.

Identity verification closes that. Your server signs each user id with a secret only it and agent44 know, your app sends the signature with every request, and while your workspace is set to Enforce, agent44 refuses a user id without a valid signature. New workspaces start with Enforce on: signed-in users are refused until you generate the secret and sign their ids (anonymous chat works from the start). If your app has no server that could sign ids, you can turn Enforce off. Either way, use user ids that can't be guessed: a random UUID or a long random string from your own database, not an email address, a username or a counting number (1042).

Who the user is#

Every request that acts for a user names them with one or both of these headers:

Header

What to send

X-A44-User-Id

Your own id for a signed-in user. The same value as external_user_id in identify. Up to 256 characters.

X-A44-Anonymous-Id

A random id you create per device or browser for someone who hasn't signed in, kept until they do. 8 to 64 characters of A–Z a–z 0–9 _ -.

X-A44-User-Hash

The user id's signature (below), on every request that sends X-A44-User-Id. Required while your workspace enforces identity verification.

A request that needs a user and sends neither is a 400. An anonymous id in the wrong format is ignored, as if it wasn't sent.

Signing in and out#

sequenceDiagram
  participant App
  participant API as api.agent44.ai
  App->>API: requests with X-A44-Anonymous-Id (visitor)
  Note over App: the user signs in
  App->>API: POST /v1/identify {external_user_id, user_hash, anonymous_id, email, name}
  API-->>App: 204 (the visitor's conversations now belong to the user)
  App->>API: requests with X-A44-User-Id and X-A44-User-Hash
  Note over App: the user signs out
  App->>API: DELETE /v1/push/devices {token} (native apps)
  Note over App: forget the user id, make a new anonymous id
  1. Before sign-in, send X-A44-Anonymous-Id. A conversation the visitor starts belongs to that anonymous contact.

  2. At sign-in, call identify with both ids (or send both headers on the next request). The anonymous contact becomes the signed-in user, or, if that user already exists, its conversations, devices, segments and timeline events move over to them.

  3. After sign-in, send X-A44-User-Id (and X-A44-User-Hash). The user sees the same conversations on every device and app that sends that id.

  4. At sign-out, remove the device's push token, stop sending the user id and start a new anonymous id, so the next person on the device doesn't see the previous user's conversations.

Identity verification#

Your workspace has one identity secret and one switch, Enforce, shared by all its iOS, Android and web apps: they share the same users, so they share the same check. Set it up in Settings › Identity verification (workspace admins).

1. Create the secret#

Click Generate secret. The secret (a44_idv_…) is shown once: copy it into your server's configuration, for example as AGENT44_IDENTITY_SECRET. It belongs on your server only, never in your app or web page: anyone with it can sign any user id.

2. Sign the user id on your server#

The signature is the lowercase hex HMAC-SHA256 of the user id, keyed with the whole secret (the a44_idv_ prefix included, as UTF-8). Sign exactly the id you send as X-A44-User-Id and external_user_id. Compute it on your server when the user signs in, and hand it to your app with the rest of the session.

// Node.js
import { createHmac } from "node:crypto";

export function agent44UserHash(userId) {
  return createHmac("sha256", process.env.AGENT44_IDENTITY_SECRET).update(userId, "utf8").digest("hex");
}
# Python
import hashlib, hmac, os

def agent44_user_hash(user_id: str) -> str:
    return hmac.new(os.environ["AGENT44_IDENTITY_SECRET"].encode(), user_id.encode(), hashlib.sha256).hexdigest()

The signature doesn't expire and is the same for a user every time, so the app can keep it with the user id.

3. Send it from the app#

  • SDKs: pass it with the user id when you identify the user (the Flutter SDK's signature:). The SDK sends it as X-A44-User-Hash on every request and as user_hash in identify.

  • Web messenger: window.agent44("identify", { userId, userHash, email, name }). See Web messenger.

  • Your own HTTP calls: the X-A44-User-Hash header on every request that sends X-A44-User-Id, and user_hash in the identify body (the header also works there).

The hash is accepted in upper or lower case. A query-string user_id (older help SDKs) is checked with the header; agent44 never reads a hash from a URL.

4. Enforce#

New workspaces start with Enforce on, before they have a secret, so build signing in from the start. For a workspace where it's off, ship the app versions that send signatures first: while Enforce is off, nothing is refused, so you can roll out safely. Once the versions in use send signatures, click Turn on Enforce (it needs a secret). From then on, for every key in the workspace:

Request

Answer

X-A44-User-Id (or external_user_id, or ?user_id=) with a valid signature

As usual

A user id with a missing or wrong signature

401 {"error": "This user couldn't be verified", "code": "identity_hash_missing"} (or identity_hash_invalid). Nothing is saved, and an anonymous visitor isn't merged into that user.

Any user id, while Enforce is on and the workspace has no secret yet

401 with "code": "identity_secret_missing": generate the secret, or turn Enforce off

Only X-A44-Anonymous-Id

As usual: visitors who haven't signed in are unaffected

Older app versions that don't send signatures then can't act for their signed-in users (their anonymous requests still work), so wait until few people use them. If agent44 can't check a signature for a moment, identified requests get a 503 with Retry-After; retry them.

Enforce is per workspace. Every key in the workspace is checked against the same setting, because a user's conversations are shared across your apps: there's no app left at Off whose key could still be used to act as your users.

Turning Enforce off#

Turn off Enforce is the opt-out for apps with no server of their own to sign ids (for example an app that only uses Firebase). User ids are then trusted as sent, by every key in the workspace, so use ids that can't be guessed. Features that look up a user's data in your own systems for the AI agent (AI data lookups) only run while Enforce is on.

Rotating the secret#

Rotate secret replaces the secret at once: signatures made with the old one stop matching. With Enforce on, every signed-in user of every app in the workspace is refused until your server signs with the new secret, so update your server straight after rotating (or turn Enforce off, rotate, deploy, then turn it back on). Rotate if the secret may have leaked.

What identify saves#

POST /v1/identify stores the user's email, name and attributes on their contact, for your team to see in the inbox and in Users, and to build segments from. Attributes are merged into what's stored: send only what changed, and send a key as null to remove it. See the Conversations API for the limits.

An email sent by identify is not verified: anyone with the key could send any address. agent44 treats it that way. It shows it to your team as given by the app, and it emails that address only to say the team replied in the app. It never uses it to decide which conversation an inbound email belongs to.

What the public key allows#

Each key belongs to one app, and every key is public: a web key is in your page's source and a mobile key is inside the app binary. The key decides:

  • The workspace. Every request reads and writes only your workspace's data.

  • The app and its platform. New conversations are recorded as coming from the key's app. Push devices are registered and removed only under the key's app. In-app messages and posts aimed at other apps are never returned, and events or replies for them are a 404.

Some things belong to the user, not the app, because one person is one contact in your workspace across all your apps:

Without identity verification enforced:

With a key of one app, someone who knows a user's id can…

Why

Read and write that user's conversations, including ones started in your other apps or on the web

So a user's history follows them across your apps. Email conversations are never available through the API.

Change their email, name and attributes with identify, and add segments and timeline events (Users API)

The contact is shared across apps. Segments can decide who a push campaign reaches, so treat them like attributes: anyone with a key and the user's id can set them.

See the roadmaps limited to that user's segments, private requests on them included (Roadmaps API)

A segment roadmap is for the people in its segments, and the id says who's asking.

Read your published help center, changelog and posts

They're published content.

The web messenger and other workspaces' keys#

The web messenger runs on your workspace's own address and refuses to run with another workspace's key: a request from it (it sends X-A44-Messenger, and the browser sends its Origin) with a key from a different workspace is a 403. Native apps and your own servers send neither, and are unaffected.

Checklist#

  • Identity verification is set up for your workspace: your server signs user ids with the workspace's secret, every app sends the signature, and Enforce is on.

  • The identity secret is only on your server.

  • User ids are random and unguessable, never emails or counting numbers.

  • You call identify with both ids when someone signs in, and reset the anonymous id when they sign out.

  • Native apps remove the push token on sign-out, with the identity headers still on the request (only the signed-in user's or this device's own token is removed).

  • Each app uses its own key. If a key is misused, revoke it in Settings › Apps (workspace admins), create a new one and ship it; a revoked key is refused at once with a 401.

  • You don't put secrets or sensitive personal data in identify attributes: your whole team can read them.

  • You render every text the API returns (messages, titles, snippets) as plain text, never as HTML.

Limits that protect you#

The API limits how fast one address, one key or one user can write, so a leaked key can't flood your inbox. A user can open at most 10 conversations a day and send 20 messages a minute; the full list is in the API overview.

Did this answer your question?