BAML is a domain-specific language for writing and testing LLM functions. The Respan integration provides both gateway routing and automatic tracing for complete LLM observability.
Configure BAML to route requests through the Respan gateway for automatic logging, or use the tracing integration to capture token usage and model information from BAML's Collector with detailed span visibility.
For gateway mode: configure a BAML client with the OpenAI provider and set the base URL to https://api.keywordsai.co/api. Use the KEYWORDSAI_API_KEY environment variable for authentication.
For tracing mode: create an instrumentation module that decorates BAML client functions with the keywordsai_baml_trace decorator. Import the decorated client before other modules to ensure comprehensive decoration.
baml
// BAML client configuration
client<llm> KeywordsAI {
provider openai
options {
model "gpt-4o"
api_key env.KEYWORDSAI_API_KEY
base_url "https://api.keywordsai.co/api"
}
}
function ExtractUser(text: string) -> User {
client KeywordsAI
prompt #"Extract user info from: {{ text }}"#
}