Generated Client
BAML generates both synchronous and asynchronous client SDKs for calling your BAML functions from Python, TypeScript, Go, and Ruby.
Basic Usage
- Python
- TypeScript
- Go
- Ruby
from baml_client import b
from baml_client.async_client import b as async_b
# Sync client
result = b.MyFunction("input")
# Async client
result = await async_b.MyFunction("input")
import { b } from 'baml_client'
// All TypeScript clients are async
const result = await b.MyFunction("input")
import b "example.com/myproject/baml_client"
ctx := context.Background()
result, err := b.MyFunction(ctx, "input")
require 'baml_client/client'
result = Baml.Client.MyFunction(input: "input")
Call Patterns
The generated client provides several call patterns:
| Pattern | Description |
|---|---|
b.Function() | Standard function call |
b.stream.Function() | Streaming response |
b.request.Function() | Get raw HTTP request without sending |
b.stream_request.Function() | Get streaming HTTP request |
b.parse.Function() | Parse raw LLM response |
b.parse_stream.Function() | Parse streaming response |
Configuration Options
Pass options to customize function calls:
| Option | Description |
|---|---|
client | Override the LLM client |
collector | Track usage and logs |
client_registry | Use custom client registry |
type_builder | Dynamic type modifications |
tags | Attach metadata to calls |
abort_controller | Cancel in-flight requests |
on_tick | Real-time progress callbacks |
Related Topics
- with_options - Configure default options
- Collector - Track function calls and usage
- TypeBuilder - Dynamic type modifications
- Async/Sync Client - Client variations