Expand description
BAML Runtime for Rust
This crate provides the runtime support for BAML-generated Rust code.
Users should not import from this crate directly - instead, use the
generated baml_client crate which re-exports necessary types.
§Derive Macros
Use #[derive(BamlEncode)] and #[derive(BamlDecode)] to automatically
implement serialization for your types:
ⓘ
use baml::{BamlEncode, BamlDecode};
#[derive(BamlEncode, BamlDecode)]
#[baml(name = "Person")]
struct Person {
name: String,
#[baml(name = "years_old")]
age: i64,
}Macros§
- baml_
unreachable - Panics with a user-friendly error message for internal/unreachable errors.
Structs§
- Async
Streaming Call - Async streaming call that yields partial results and a final response
- Audio
- Audio media type
- Baml
Runtime - Handle to the BAML runtime
- Cancellation
Token - Token for checking, waiting on, and triggering cancellation.
- Check
- Individual check result
- Checked
- Result of a @check constraint
- Class
Builder - Builder for class types
- Class
Property Builder - Builder for class properties
- Client
Registry - A registry for configuring LLM clients at runtime.
- Collector
- Collector for gathering telemetry from function calls
- Dynamic
Class - A fully dynamic class - all fields accessed via .
get() - Dynamic
Enum - A dynamic enum - name and value as strings
- Dynamic
Union - A dynamic union - wraps a value with union metadata
- Enum
Builder - Builder for enum types
- Enum
Value Builder - Builder for enum values
- Function
Args - Arguments for a BAML function call
- Function
Log - Log entry for a function call
- HTTP
Body - HTTP request or response body
- HTTP
Request - HTTP request details
- HTTP
Response - HTTP response details
- Image
- Image media type
- LLMCall
- Details of a single LLM API call
- LLMStream
Call - Details of a streaming LLM API call
- PDF media type
- SSEResponse
- Server-Sent Event response chunk
- Stream
State - Streaming state wrapper for @
stream.with_state - Stream
Timing - Timing information for a streaming call
- Streaming
Call - Result of a streaming function call
- Timing
- Timing information for a function or LLM call
- Type
Builder - Builder for constructing BAML types at runtime
- TypeDef
- A dynamically constructed BAML type
- Usage
- Token usage statistics
- Video
- Video media type
Enums§
- Baml
Error - BAML runtime errors
- Baml
Value - A dynamically-typed BAML value, parameterized by two type enums:
- Check
Status - Status of a check constraint
- LLMCall
Kind - Either an
LLMCallorLLMStreamCall - LogType
- Type of function log entry
- Stream
Event - Event from a streaming function call
- Streaming
State - Current streaming state
Traits§
- Baml
Class - Helper trait for decoding BAML classes
- Baml
Decode - Trait for decoding from CFFI protobuf format (BAML -> Rust)
- Baml
Encode - Trait for encoding to CFFI protobuf format (Rust -> BAML)
- Baml
Enum - Helper trait for decoding BAML enums
- Baml
Serialize MapKey - From
Baml Value - Trait for extracting concrete types from
BamlValue. - From
Baml Value Ref - Trait for zero-copy borrowing from
BamlValue. - Known
Types - Trait for project-specific known types enum.
Implemented by
CodeGen’dTypesandStreamTypesenums.
Functions§
- decode_
enum - Decode an enum from a
CffiValueHolder - decode_
field - Helper for decoding a field from a class’s fields map
- encode_
class - Encode a class to
HostValue - encode_
class_ dynamic - Encode a class with dynamic field names (for dynamic classes that flatten __dynamic fields)
- encode_
enum - Encode an enum to
HostValue - invoke_
cli - Call baml-cli with the given arguments Returns the exit code
- version
- Get the BAML library version
Type Aliases§
Derive Macros§
- Baml
Decode - Derive macro for
BamlDecodetrait. - Baml
Encode - Derive macro for
BamlEncodetrait.