# Session

> User sessions: a short-lived token for one user, safe to hand to a browser.

```python
session = user.session(scopes=["agents", "humans"], ttl_s=3600)
token = session.token                       # your frontend uses it as its API key

client = noclick.Client.for_session(session)     # or act as that user from Python
```

## Session

```typescript
class Session
```

A token pinned to one user with a subset of the minting key's scopes. Printing it never shows the token.

| Attribute | Type | Description |
| --- | --- | --- |
| `token` | `string` |  |
| `id` | `string | null` |  |
| `userId` | `string | null` |  |
| `scopes` | `string[]` |  |
| `expiresAt` | `Date | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |
| `baseUrl` | `string | undefined` | The API the session was minted on. |
| `expired` | `boolean` | Whether `expiresAt` has passed (by this machine's clock). |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### Session.client

```typescript
client(options?: Omit<ClientOptions, "apiKey">): NoClick
```

A client that acts as this session: `await Agent.list({ client: session.client() })`.

Parameters:

- `options.baseUrl` (`string`): Defaults to `NOCLICK_API_URL`, then `https://api.noclick.com`.
- `options.timeoutMs` (`number`): Per-attempt request timeout (default 60s).
- `options.maxRetries` (`number`): Retries for 408/429/5xx (never a POST's 500, which is replayed) and network errors (default 3).
- `options.backoffMs` (`number`): First backoff step; doubles per attempt with jitter (default 500ms).
- `options.maxBackoffMs` (`number`)
- `options.headers` (`Record<string, string>`)
- `options.fetch` (`typeof fetch`): A custom `fetch` (a proxy agent, a test double). Defaults to the global one.

Returns: A client holding the session's token, pointed at the API the session came from. Every
call it makes acts as the session's user, with the session's scopes.
