# SessionId
Source: https://docs.maelstrom-ai.co/dev/reference/protocol/variables/sessionid/
Documentation revision: 89a8f5e9d10cedcf0b30376d7846113f06f26120
SDK manifests in this build: @maelstrom-co/react@0.2.1, @maelstrom-co/client@0.2.1, @maelstrom-co/connectors@0.2.1, @maelstrom-co/protocol@0.2.1, @maelstrom-co/engine@0.2.1
These docs follow this source revision. Manifest versions do not prove release compatibility; verify the installed package exports before using an API.

> **SessionId**: (`value?`) => [`SessionId`](https://docs.maelstrom-ai.co/dev/reference/protocol/type-aliases/sessionid/)

Defined in: [packages/protocol/src/lib/session.ts:10](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/protocol/src/lib/session.ts#L10)

Creates or brands a SessionId. Smart constructor — the identifier `SessionId` refers to both the type (for type annotations) and the factory (for runtime creation), exploiting TypeScript’s separate type/value namespaces.

-   Called with no arguments: generates a new unique session ID with a `session-` prefix for easy log grepping.
-   Called with an existing string: brands it as a SessionId without changing its value. Use this when the developer brings their own ID (DB row ID, user ID, persisted localStorage value, etc.) or when rehydrating from serialized data.

## Parameters

### value?

`string`

## Returns

[`SessionId`](https://docs.maelstrom-ai.co/dev/reference/protocol/type-aliases/sessionid/)

## Example

```ts
const fresh = SessionId();               // 'session-<nanoid>'
const fromDb = SessionId(row.sessionId); // brands an existing id
```
