Skip to main content
batched_completions sends many chat requests through a provider’s batch API. Batches cost about half as much as regular calls and finish within 24 hours. Other providers raise BadRequestError.

Run a batch and wait

  • Each request takes the same arguments as completion, and is built exactly as a direct call would be.
  • Keyword arguments such as api_key or temperature apply to every request.
  • The call polls every poll_interval seconds (30 by default) and returns one ChatCompletion per request, in request order.
  • A request that failed comes back as its RouteHub exception without failing the rest.
  • It raises Timeout after timeout seconds (24 hours by default). The batch keeps running and you can still collect it.

Submit now, collect later

Pass wait=False to get a BatchJob back at once:
BatchJob has status(), results() and cancel(). Another process can collect the work from the provider name and batch ID:

Async

await routehub.abatched_completions(...) takes the same arguments and keeps the event loop free while the batch runs.