bentoml
An unofficial async Rust client for BentoML services (GitHub).
BentoML services expose their @bentoml.api methods as HTTP POST endpoints whose
route is derived from the method name. Because endpoints are defined dynamically
per-service, this crate doesn't generate typed bindings: instead you name a route
with client.endpoint(route) (or client.task(route) for an @bentoml.task) and
call it over your own serde types.
Features
- Typed calls:
endpoint(route).invoke(&payload)over your ownserderequest and response types, with no codegen or per-service bindings. - Async task queues:
client.task(route)submits@bentoml.taskjobs, then poll status, fetch results, retry, or cancel through aTaskHandle. The synchronous and task surfaces are distinct handle types, socallandsubmitcan't be mixed. - File and streaming I/O:
multipart/form-datafile inputs, raw-binary root inputs, binary responses, and chunked streaming endpoints (featurestream). - Resilient transport: exponential-backoff retries via
reqwest-middleware, bearer-token auth, an optional per-request timeout, and a cheap-to-cloneArc-backed client.
Usage
Add the dependency:
[]
= "0.5"
= { = "1", = ["macros", "rt-multi-thread"] }
= { = "1", = ["derive"] }
The minimum supported Rust version (MSRV) is 1.91.
use *;
use ;
async
A handle names the route once; calls are made on it. See examples/ for
runnable examples.
Capabilities
The handle's kind mirrors the BentoML decorator, and decides which methods are
available — call is not callable on a task handle, nor submit on an api handle.
A Client::endpoint(route) handle (@bentoml.api) covers the synchronous surface:
call/call_bytes/call_multipart: send a JSON, raw-binary, ormultipart/form-databody (built withmultipart::Multipart), returning anEndpointReplyyou read as.json::<R>(),.bytes(),.text(), or (featurestream).stream()— so input and output encodings are chosen independently.invoke: the JSON-in, JSON-out shorthand —invoke(&p)deserializes the response for you, equivalent tocall(&p).await?.json().await?.
A Client::task(route) handle (@bentoml.task) covers the async task surface:
submit/submit_bytes/submit_multipart: submit a JSON, raw-binary, ormultipart/form-datatask input; return aTaskHandleforstatus,wait,retry,cancel, and a result read asjson::<R>()/bytes()/text().
EndpointReply::stream() yields a ByteStream of response chunks; decode it with
.text(), .lines(), or .json::<T>().
The Client itself provides health checks: is_ready / is_live and
wait_until_ready.
These are gated by feature flags:
rustls-tls(default): HTTPS via Rustls.native-tls: HTTPS via the platform-native TLS stack.stream: response streaming viaEndpointReply::stream.tracing:#[tracing::instrument]spans on request methods, including anyx-request-idas arequest_idfield.
Changelog
See CHANGELOG.md for release notes and version history.
License
Licensed under the MIT License.