AsyncClient / SyncClient
AsyncClient / SyncClient
AsyncClient / SyncClient
BAML generates both a sync client and an async client. They offer the exact same public API but methods are either synchronous or asynchronous.
The generated client exposes all the functions that you’ve defined your BAML
files as methods. Suppose we have this file named baml_src/literature.baml:
After running baml-cli generate you can directly call these functions from
your code. Here’s an example using the async client:
The sync client is exactly the same but it doesn’t need an async runtime, instead it just blocks.
The client object exposes some references to other objects that call your functions in a different manner.
.streamThe .stream object is used to stream the response from a function.
.requestThis feature was added in: v0.79.0
The .request object returns the raw HTTP request but it does not send it.
However, the async client still returns an awaitable object because we might
need to resolve media types like images and convert them to base64 or the
required format in order to send them to the LLM.
.stream_requestThis feature was added in: v0.79.0
Same as .request but sets the streaming options to true.
.parseThis feature was added in: v0.79.0
The .parse object is used to parse the response returned by the LLM after
the function call. Can be used in combination with .request.
.parse_streamThis feature was added in: v0.79.0
Same as .parse but for streaming responses. Can be used in
combination with .stream_request.