Skip to main content
HTTP client for direct API endpoints. Sends JSON payloads to a model server via plain HTTP POST using requests (synchronous) and aiohttp (asynchronous).

HTTPClient

class HTTPClient()
Sends JSON payloads over HTTP. Fully configured at construction — predict / embed only need the serialized body.
base_url
Root URL of the model server, e.g. "http://localhost:8080".
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.
timeout
HTTP request timeout in seconds.
Example:
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

def close() -> None
Closes the underlying HTTP session and releases connections.

predict

def predict(body: str) -> str
POST to the prediction endpoint.
body
str
required
Serialized JSON request payload.
returns
str
Response body as a JSON string.

embed

def embed(body: str) -> str
POST to the embedding endpoint.
body
str
required
Serialized JSON request payload.
returns
str
Response body as a JSON string.

metadata

def metadata() -> str
GET the metadata endpoint.
returns
str
Response body as a JSON string.

predict_async

async def predict_async(body: str, session: Any = None) -> str
POST to the prediction endpoint asynchronously.
body
str
required
Serialized JSON request payload.
session
Any
An ClientSession for connection pooling.
returns
str
Response body as a JSON string.

embed_async

async def embed_async(body: str, session: Any = None) -> str
POST to the embedding endpoint asynchronously.
body
str
required
Serialized JSON request payload.
session
Any
An ClientSession for connection pooling.
returns
str
Response body as a JSON string.