> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bioptimus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# http

HTTP client for direct API endpoints.

Sends JSON payloads to a model server via plain HTTP POST using `requests` (synchronous) and `aiohttp` (asynchronous).

## HTTPClient

```python theme={null}
class HTTPClient()
```

Sends JSON payloads over HTTP.

Fully configured at construction — `predict` / `embed` only need the serialized body.

<ParamField body="base_url">
  Root URL of the model server, e.g. `"http://localhost:8080"`.
</ParamField>

<ParamField body="endpoints">
  Mapping of endpoint type to path, e.g. `{"prediction": "/api/predict/m-optimus", "embedding": "/api/embed/m-optimus"}`. At least one key must be present.
</ParamField>

<ParamField body="timeout">
  HTTP request timeout in seconds.
</ParamField>

**Example:**

```python theme={null}
client = HTTPClient(
    "http://localhost:8080",
    endpoints={
        "prediction": "/api/predict/m-optimus",
        "embedding": "/api/embed/m-optimus",
    },
)
pred_json = client.predict(request_json)
emb_json = client.embed(request_json)
```

#### close

```python theme={null}
def close() -> None
```

Closes the underlying HTTP session and releases connections.

#### predict

```python theme={null}
def predict(body: str) -> str
```

POST to the prediction endpoint.

<ParamField body="body" type="str" required>
  Serialized JSON request payload.
</ParamField>

<ResponseField name="returns" type="str">
  Response body as a JSON string.
</ResponseField>

#### embed

```python theme={null}
def embed(body: str) -> str
```

POST to the embedding endpoint.

<ParamField body="body" type="str" required>
  Serialized JSON request payload.
</ParamField>

<ResponseField name="returns" type="str">
  Response body as a JSON string.
</ResponseField>

#### metadata

```python theme={null}
def metadata() -> str
```

GET the metadata endpoint.

<ResponseField name="returns" type="str">
  Response body as a JSON string.
</ResponseField>

#### predict\_async

```python theme={null}
async def predict_async(body: str, session: Any = None) -> str
```

POST to the prediction endpoint asynchronously.

<ParamField body="body" type="str" required>
  Serialized JSON request payload.
</ParamField>

<ParamField body="session" type="Any">
  An `ClientSession` for connection pooling.
</ParamField>

<ResponseField name="returns" type="str">
  Response body as a JSON string.
</ResponseField>

#### embed\_async

```python theme={null}
async def embed_async(body: str, session: Any = None) -> str
```

POST to the embedding endpoint asynchronously.

<ParamField body="body" type="str" required>
  Serialized JSON request payload.
</ParamField>

<ParamField body="session" type="Any">
  An `ClientSession` for connection pooling.
</ParamField>

<ResponseField name="returns" type="str">
  Response body as a JSON string.
</ResponseField>
