Assign a support category to an incoming message.
Create a Canary project first. This example uses OpenAI and requires an OPENAI_API_KEY.
Source
Put this code in baml_src/main.baml:
classify-support-tickets.bamlenum Category {
Refund
CancelOrder
TechnicalSupport
AccountIssue
Question
}
function classify_message(input: string) -> Category {
client: openai.ResponsesClient.new(model = "gpt-4.1-mini", api_key = env.OPENAI_API_KEY)
prompt: `
${role("system")}
Classify the support message into one category.
${ctx.output_format()}
${role("user")}
${input}
`
}enum Category {
Refund
CancelOrder
TechnicalSupport
AccountIssue
Question
}
function classify_message(input: string) -> Category {
client: openai.ResponsesClient.new(model = "gpt-4.1-mini", api_key = env.OPENAI_API_KEY)
prompt: `
${role("system")}
Classify the support message into one category.
${ctx.output_format()}
${role("user")}
${input}
`
}Call it
From the project root:
The expected category is Refund; model responses can vary.
For Node.js, generate the TypeScript SDK, then call the async export:
Why this shape
An enum limits the result to the categories you declare. Your application can switch on those values without parsing free-form model text.
Read the function reference for syntax details or expand the same pattern in the structured extraction tutorial.