Skip to content

Function: generateId()

@providerprotocol/ai


@providerprotocol/ai / utils / generateId

generateId(): string

Defined in: src/utils/id.ts:25

Generates a unique UUID v4 identifier.

Uses the native crypto.randomUUID() when available for cryptographically secure randomness. Falls back to a Math.random-based implementation for environments without Web Crypto API support.

string

A UUID v4 string in the format xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx

const messageId = generateId();
// => "f47ac10b-58cc-4372-a567-0e02b2c3d479"