Crate baml

Crate baml 

Source
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§

AsyncStreamingCall
Async streaming call that yields partial results and a final response
Audio
Audio media type
BamlRuntime
Handle to the BAML runtime
CancellationToken
Token for checking, waiting on, and triggering cancellation.
Check
Individual check result
Checked
Result of a @check constraint
ClassBuilder
Builder for class types
ClassPropertyBuilder
Builder for class properties
ClientRegistry
A registry for configuring LLM clients at runtime.
Collector
Collector for gathering telemetry from function calls
DynamicClass
A fully dynamic class - all fields accessed via .get()
DynamicEnum
A dynamic enum - name and value as strings
DynamicUnion
A dynamic union - wraps a value with union metadata
EnumBuilder
Builder for enum types
EnumValueBuilder
Builder for enum values
FunctionArgs
Arguments for a BAML function call
FunctionLog
Log entry for a function call
HTTPBody
HTTP request or response body
HTTPRequest
HTTP request details
HTTPResponse
HTTP response details
Image
Image media type
LLMCall
Details of a single LLM API call
LLMStreamCall
Details of a streaming LLM API call
Pdf
PDF media type
SSEResponse
Server-Sent Event response chunk
StreamState
Streaming state wrapper for @stream.with_state
StreamTiming
Timing information for a streaming call
StreamingCall
Result of a streaming function call
Timing
Timing information for a function or LLM call
TypeBuilder
Builder for constructing BAML types at runtime
TypeDef
A dynamically constructed BAML type
Usage
Token usage statistics
Video
Video media type

Enums§

BamlError
BAML runtime errors
BamlValue
A dynamically-typed BAML value, parameterized by two type enums:
CheckStatus
Status of a check constraint
LLMCallKind
Either an LLMCall or LLMStreamCall
LogType
Type of function log entry
StreamEvent
Event from a streaming function call
StreamingState
Current streaming state

Traits§

BamlClass
Helper trait for decoding BAML classes
BamlDecode
Trait for decoding from CFFI protobuf format (BAML -> Rust)
BamlEncode
Trait for encoding to CFFI protobuf format (Rust -> BAML)
BamlEnum
Helper trait for decoding BAML enums
BamlSerializeMapKey
FromBamlValue
Trait for extracting concrete types from BamlValue.
FromBamlValueRef
Trait for zero-copy borrowing from BamlValue.
KnownTypes
Trait for project-specific known types enum. Implemented by CodeGen’d Types and StreamTypes enums.

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§

StaticRuntimeType

Derive Macros§

BamlDecode
Derive macro for BamlDecode trait.
BamlEncode
Derive macro for BamlEncode trait.