> This page is for version Main (default).
> For other versions, use one of these documentation indexes:
> - Main (default): https://docs.nvidia.com/nemo/gym/main/llms.txt
> - 0.7.0: https://docs.nvidia.com/nemo/gym/v0.7.0/llms.txt
> - 0.6.0: https://docs.nvidia.com/nemo/gym/v0.6.0/llms.txt
> - 0.5.1: https://docs.nvidia.com/nemo/gym/v0.5.1/llms.txt
> - 0.5.0: https://docs.nvidia.com/nemo/gym/v0.5.0/llms.txt
> - 0.4.0: https://docs.nvidia.com/nemo/gym/v0.4.0/llms.txt
> - 0.3.0: https://docs.nvidia.com/nemo/gym/v0.3.0/llms.txt
> - 0.2.1: https://docs.nvidia.com/nemo/gym/v0.2.1/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/gym/llms.txt.

# nemo_gym.server_runtime.request_handling.session_id

Middleware that gives every request's session a Gym session ID.

## Module Contents

### Classes

| Name                                                                                              | Description                                                                                          |
| ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| [`SessionIDMiddleware`](#nemo_gym-server_runtime-request_handling-session_id-SessionIDMiddleware) | Assign the session ID before the route runs, and settle it when the reply starts.                    |
| [`_ReplyReplaced`](#nemo_gym-server_runtime-request_handling-session_id-_ReplyReplaced)           | Stops a route whose reply the 409 for another worker's session replaced, so it streams nothing more. |

### API

```python
class nemo_gym.server_runtime.request_handling.session_id.SessionIDMiddleware(
    app: starlette.types.ASGIApp
)
```

Assign the session ID before the route runs, and settle it when the reply starts.

`SessionMiddleware` must wrap this middleware.
It puts the session in `scope["session"]`, and writes the cookie when the reply starts, after this middleware has
settled the session.

```python
nemo_gym.server_runtime.request_handling.session_id.SessionIDMiddleware.__call__(
    scope: starlette.types.Scope,
    receive: starlette.types.Receive,
    send: starlette.types.Send
) -> None
```

async

```python
class nemo_gym.server_runtime.request_handling.session_id._ReplyReplaced()
```

Exception

**Bases:** `Exception`

Stops a route whose reply the 409 for another worker's session replaced, so it streams nothing more.