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_keyortemperatureapply to every request. - The call polls every
poll_intervalseconds (30 by default) and returns oneChatCompletionper request, in request order. - A request that failed comes back as its RouteHub exception without failing the rest.
- It raises
Timeoutaftertimeoutseconds (24 hours by default). The batch keeps running and you can still collect it.
Submit now, collect later
Passwait=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.