Type mappings, generated client calls, streaming behavior, and TypeScript-specific boundaries.
Compatibility
Generate the TypeScript client with the same BAML toolchain selected by the project. Application code imports generated symbols locally; the runtime package provides the supporting media and execution types.
| Concern | TypeScript behavior |
|---|---|
| Calls | Generated methods are asynchronous and return promises. |
| Names | BAML function and type names remain visible in generated code. |
| Regeneration | Generated files are replaced; application edits belong elsewhere. |
Type mappings
| BAML | TypeScript | Notes |
|---|---|---|
string | string | Text values map directly. |
int / float | number | Keep integer constraints in mind at runtime boundaries. |
T[] | T[] | Element types remain explicit. |
T? | Nullable generated type | Do not use truthiness when zero or empty text is valid. |
class | Generated object type | Fields preserve their declared names and types. |
enum | Generated enum | Import the generated symbol instead of duplicating literals. |
Generated client
Import b from the generated client directory and await the method matching the BAML function name.
import { b } from "./baml_client"
import type { Category } from "./baml_client/types"
export async function classify(input: string): Promise<Category> {
return b.ClassifyMessage(input)
}Streaming
Streaming calls live under b.stream. The generated stream API exposes incremental values and a final typed result; use the adapter appropriate to the application framework at its outer boundary.
const stream = b.stream.ClassifyMessage(input)
const response = stream.toStreamable()Transition rules
- Generated client calls return promises; await them before using the typed result.
- Regenerate after changing a BAML function, class, enum, or generator configuration.
- Treat partial streaming values separately from the final typed result.
Gotchas
- Never edit generated client files by hand.
- Keep secret-bearing client construction on the server side of web applications.
- Do not use truthiness to test nullable numbers or strings when zero or empty text is valid.
- Import generated enum symbols instead of duplicating their literal values.
Continue with the function reference to review the source declaration behind generated calls.