> This page is for version 0.4.0.
> 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.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/gym/_mcp/server.

# nemo_gym.client.server_client

`ServerClient`, which finds Gym servers through the head server and calls them, and server URLs.

## Module Contents

### Classes

| Name                                                          | Description |
| ------------------------------------------------------------- | ----------- |
| [`ServerClient`](#nemo_gym-client-server_client-ServerClient) | -           |

### Functions

| Name                                                                                      | Description                                                                                                      |
| ----------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| [`_connectable_client_host`](#nemo_gym-client-server_client-_connectable_client_host)     | Return a connectable client host for a server bind address.                                                      |
| [`apply_rollout_prefix`](#nemo_gym-client-server_client-apply_rollout_prefix)             | Append the rollout prefix and, while traces export, the current span's trace context to a model-server root URL. |
| [`get_server_url`](#nemo_gym-client-server_client-get_server_url)                         | -                                                                                                                |
| [`rollout_path_prefix`](#nemo_gym-client-server_client-rollout_path_prefix)               | Return the leading model-server path prefix for a rollout, if available.                                         |
| [`setup_server_client`](#nemo_gym-client-server_client-setup_server_client)               | -                                                                                                                |
| [`trace_context_path_segment`](#nemo_gym-client-server_client-trace_context_path_segment) | Return `/ng-trace/&lt;traceparent&gt;` for the current span, or `""` while traces are off or no span is current. |

### Data

[`NEMO_GYM_MODEL_SERVER_BASE_URL_ENV_VAR_NAME`](#nemo_gym-client-server_client-NEMO_GYM_MODEL_SERVER_BASE_URL_ENV_VAR_NAME)

[`NEMO_GYM_MODEL_SERVER_NAME_ENV_VAR_NAME`](#nemo_gym-client-server_client-NEMO_GYM_MODEL_SERVER_NAME_ENV_VAR_NAME)

[`SESSION_ID_KEY`](#nemo_gym-client-server_client-SESSION_ID_KEY)

[`ServerStatus`](#nemo_gym-client-server_client-ServerStatus)

[`_TRACEPARENT_PATTERN`](#nemo_gym-client-server_client-_TRACEPARENT_PATTERN)

[`logger`](#nemo_gym-client-server_client-logger)

### API

```python
class nemo_gym.client.server_client.ServerClient()
```

**Bases:** `BaseModel`

**`_checkpoint_enabled`** `Optional[bool] = PrivateAttr(default=None)`

---

**`_server_base_urls`** `dict[str, str] = PrivateAttr(default_factory=dict)`

---

**`global_config_dict`** `DictConfig`

---

**`head_server_config`** `BaseServerConfig`

---

**`model_config`** `= ConfigDict(arbitrary_types_allowed=True)`

---

```python
nemo_gym.client.server_client.ServerClient._build_server_base_url(
    server_config_dict: omegaconf.OmegaConf
) -> str
```

```python
nemo_gym.client.server_client.ServerClient._client_host(
    host: str
) -> str
```

staticmethod

Return a connectable host for a server bind address.

Wildcard addresses are valid for binding a server but are not valid
advertised client targets. In particular, proxy-aware HTTP clients can
route `0.0.0.0` through an external proxy instead of reaching the
local server.

```python
nemo_gym.client.server_client.ServerClient._resolve_base_url(
    server_name: str
) -> str
```

```python
nemo_gym.client.server_client.ServerClient.assistant_message_header(
    model_server_name: str
) -> bytes | None
```

Read the optional header property of harnesses using this model server.

The property lives on the harness package so model workers need not import
an agent's app or install its runtime dependencies.

```python
nemo_gym.client.server_client.ServerClient.checkpoint_enabled() -> bool
```

Return whether the global `checkpoint:` block enables partial-rollout checkpointing.

```python
nemo_gym.client.server_client.ServerClient.get(
    server_name: str,
    url_path: str,
    kwargs: typing.Unpack[aiohttp.client._RequestOptions] = {}
) -> aiohttp.ClientResponse
```

async

Args:
server_name: str
The name of the server you are trying to call.
url_path: str
The URL path in the server you are trying to call e.g. "/v1/responses".

```python
nemo_gym.client.server_client.ServerClient.load_from_global_config(
    head_server_config: typing.Optional[nemo_gym.config.config_types.BaseServerConfig] = None
) -> nemo_gym.client.server_client.ServerClient
```

classmethod

Build a client from the fully resolved global config.

Gym-launched server processes reuse the config injected by their parent.
Other processes fetch the config from the head server.

```python
nemo_gym.client.server_client.ServerClient.load_head_server_config() -> nemo_gym.config.config_types.BaseServerConfig
```

classmethod

```python
nemo_gym.client.server_client.ServerClient.model_post_init(
    context: typing.Any
) -> None
```

```python
nemo_gym.client.server_client.ServerClient.poll_for_status(
    server_name: str,
    timeout_seconds: float = 5
) -> nemo_gym.client.server_client.ServerStatus
```

```python
nemo_gym.client.server_client.ServerClient.post(
    server_name: str,
    url_path: str,
    kwargs: typing.Unpack[aiohttp.client._RequestOptions] = {}
) -> aiohttp.ClientResponse
```

async

Args:
server_name: str
The name of the server you are trying to call.
url_path: str
The URL path in the server you are trying to call e.g. "/v1/responses".

```python
nemo_gym.client.server_client.ServerClient.request(
    server_name: str,
    url_path: str,
    method: str,
    _control: bool = False,
    _resend_after_disconnect: bool = True,
    kwargs: typing.Unpack[aiohttp.client._RequestOptions] = {}
) -> aiohttp.ClientResponse
```

async

Call another server. `_control` sends the call over the reserved control pool.

```python
nemo_gym.client.server_client._connectable_client_host(
    host: str
) -> str
```

Return a connectable client host for a server bind address.

```python
nemo_gym.client.server_client.apply_rollout_prefix(
    base_url: str,
    rollout_id: typing.Optional[str],
    token_capture: bool = False,
    trace_context: bool = True
) -> str
```

Append the rollout prefix and, while traces export, the current span's trace context to a model-server root URL.

Every caller hands the result to a client Gym does not instrument (a harness in a sandbox, a
third-party client library), which is why the trace context travels in the URL here; Gym's own
clients send the `traceparent` header instead and use `url_path_for_run`.

The span named is the one current when the URL is built, so pass `trace_context=False` for a
URL that is built once and reused across rollouts (a cached client): otherwise every later
rollout's calls would be parented to the first one's span.

```python
nemo_gym.client.server_client.get_server_url(
    server_name: str
) -> str
```

```python
nemo_gym.client.server_client.rollout_path_prefix(
    rollout_id: typing.Optional[str],
    token_capture: bool = False
) -> str
```

Return the leading model-server path prefix for a rollout, if available.

```python
nemo_gym.client.server_client.setup_server_client(
    head_server_config: typing.Optional[nemo_gym.config.config_types.BaseServerConfig] = None
) -> nemo_gym.client.server_client.ServerClient
```

```python
nemo_gym.client.server_client.trace_context_path_segment() -> str
```

Return `/ng-trace/<traceparent>` for the current span, or `""` while traces are off or no span is current.

`TraceContextPathMiddleware` on the receiving Gym server turns it back into the header.

```python
nemo_gym.client.server_client.NEMO_GYM_MODEL_SERVER_BASE_URL_ENV_VAR_NAME = 'NEMO_GYM_MODEL_SERVER_BASE_URL'
```

```python
nemo_gym.client.server_client.NEMO_GYM_MODEL_SERVER_NAME_ENV_VAR_NAME = 'NEMO_GYM_MODEL_SERVER_NAME'
```

```python
nemo_gym.client.server_client.SESSION_ID_KEY = 'session_id'
```

```python
nemo_gym.client.server_client.ServerStatus = Union[Literal['success'], Literal['connection_error'], Literal['timeout'], Liter...
```

```python
nemo_gym.client.server_client._TRACEPARENT_PATTERN = '00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}'
```

```python
nemo_gym.client.server_client.logger = logging.getLogger(__name__)
```