Package & serve AI models as APIs · @service / @api · Bentos · containerize · verified against BentoML 1.4.x (2026)

BentoML cheat sheet

BentoML turns a model-inference script into a production REST API with a couple of decorators. Wrap a class in @bentoml.service, mark methods with @bentoml.api, and type-hint the I/O — BentoML gives you a server with validation, docs, adaptive batching, and streaming. Package everything (code + models + env) into a versioned Bento, then containerize to Docker or deploy to BentoCloud. Targets the modern 1.4.x service API (the class-based successor to the old Runner API), Python 3.9+.

service & API serving features models & config package & ship deploy & ecosystem gotcha most common

Verified 2026-08-31 against the official docs at docs.bentoml.com (BentoML 1.4.39, released 2026-05-07). This sheet uses the current @bentoml.service class API; the pre-1.2 bentoml.Runner/Service(api=...) style is legacy.

Outline

Write a @bentoml.service class, wire models & config, then build a Bento and containerize or deploy it.

Build a service

  1. 1Install & first service
  2. 2@service & @api
  3. 3Inputs & outputs

Serving features

  1. 4Streaming & batching
  2. 5Tasks & ASGI mount

Models & config

  1. 6Model store
  2. 7Service config
  3. 8Composition (depends)

Package & ship

  1. 9Build config (bentofile)
  2. 10serve, build & containerize

Deploy & ecosystem

  1. 11BentoCloud & deploy
  2. 12Ecosystem

Build a Service

A service is a Python class; its methods become validated HTTP endpoints.

1Install & first serviceservice.py
2@service & @apithe two decorators
3Inputs & outputstype hints = schema

Serving Features

Stream tokens, batch requests for throughput, and offload long jobs.

4Streaming & batchingthroughput
5Tasks & ASGI mountbeyond request/response

Models & Config

Version models in the store, size the runtime, and compose services.

6Model storeversion models
7Service configresources / scaling
8Composition (depends)multi-service

Package & Ship

Freeze code + models + environment into a Bento, then a container.

9Build config (bentofile)reproducible env
10serve, build & containerizeCLI flow

Deploy & Ecosystem

One command to the cloud, plus where BentoML fits with other tools.

11BentoCloud & deployto production
12Ecosystemplays well with

Worth memorizing

@bentoml.serviceclass = a deployable service
@bentoml.apimethod = a validated HTTP endpoint
type hintsdefine request/response schema (Pydantic)
__init__load models once per worker
yieldgenerator return = streaming (SSE)
batchable=Trueadaptive batching for throughput
bentoml.models.getload versioned model from the store
bentoml.depends()compose services (replaces Runners)
resources / traffic@service(...) sizing + autoscale signal
bentoml buildcode+models+env -> versioned Bento
bentoml containerizeBento -> Docker image
bentoml deployship to BentoCloud w/ autoscaling