mint_handle

View as MarkdownOpen in Claude

Issue a signed handle for a new conversation, generating a conversation id when you don’t supply one. The handle carries the id and an expiry, signed with the gateway’s HMAC secret.

The browser never names a conversation. If it did, a publishable key plus a guessed id would be enough to continue someone else’s chat, so signing means a caller can only present handles this gateway issued.

The router mints handles for you. Reach for this when you want to hand a page a handle for a conversation your server already started.

Parameters

conversation_id
str | None

The conversation to bind the handle to. Generates a random id when omitted.

Returns

str — the signed handle, in the form <payload>.<signature>, both base64url.

Example

1from signalwire.ai_chat import ChatGateway
2
3gateway = ChatGateway(
4 config_url="https://bayview-taxi.example.com/swml",
5 secret="a-stable-secret-across-replicas",
6)
7
8handle = gateway.mint_handle("chat-8f21")
9# hand `handle` to the page; it sends it back on every later call

Read one back with read_handle().