Day 6: BoxLang AI: One Fluent API for Every AI Provider 🎄
BoxLang AI gives you a unified, consistent way to work with Large Language Models—across multiple providers—using a single functional and fluent API. Build AI-powered features directly into your BoxLang apps without juggling different SDKs, formats, or request models.
You can also extend capabilities with bx-aiplus, part of our BoxLang + / ++ subscriptions, which adds more providers, advanced features, and enhancements.
License
BoxLang is open source under the Apache 2 License.
Getting Started
Install the module:
install-bx-module bx-ai
For CommandBox-based web apps:
box install bx-ai
Once installed, simply use the AI global functions in your BoxLang code:
answer = aiChat( "How amazing is BoxLang?" )
println( answer )
Supported Providers
You can use any of these AI providers (API key required):
- Claude (Anthropic)
- DeepSeek
- Gemini
- Grok
- OpenAI
- Perplexity
More providers are available through bx-aiplus.
Features
- Unified API for multiple AI providers
- Fluent, functional interface
- Build structured chat requests
- Compose messages programmatically
- Async chat with futures
- Real-time tools for function calling
- Global defaults
- Custom AI service objects
- And more
Real-Time Tooling Support
| Provider | Tools |
|---|---|
| Claude | Yes |
| DeepSeek | Yes |
| Gemini | Coming Soon |
| Grok | Yes |
| OpenAI | Yes |
| Perplexity | Yes |
Configuration (boxlang.json)
You can control defaults globally:
{
"modules" : {
"bxai" : {
"settings": {
"provider" : "openai",
"apiKey" : "",
"defaultParams" : {},
"timeout" : 30,
"logRequest" : false,
"logResponse" : false,
"logRequestToConsole" : false,
"logResponseToConsole" : false,
"returnFormat" : "single"
}
}
}
}
Return Formats
Choose how responses should return:
- single – Returns one string (default)
- all – Returns all messages as an array
- raw – Full provider response for debugging or custom processing
Global Functions (BIFs)
aiChat()
Basic chat request
Return: string/array/struct based on format
aiChatAsync()
Async version with futures
aiChatRequest()
Build raw ChatRequest objects for full control
aiMessage()
Build fluent message objects
aiService()
Create or override AI provider service objects
aiTool()
Create function-calling tools for real-time processing
Quick Examples
Simple chat
result = aiChat( "Hello, world!" )
Async chat
aiChatAsync( "Hello!" )
.then( r -> println(r) )
Fluent message building
msg = aiMessage()
.system( "Be helpful" )
.user( "Hello" )
Custom service
service = aiService( "openai", "my-key" )
.defaults( { temperature: 0.7 } )
Tool example
tool = aiTool( "weather", "Get weather data", location => getWeather(location) )
aiChat() and aiChatAsync()
messages can be:
- A string
- A struct
{ role, content } - An array of message structs
- A ChatMessage object
You can customize:
- Provider
- API key
- Timeout
- Logging
- Return format
- Provider request params (model, temperature, etc.)
Examples
aiChat( "Write a haiku about recursion." )
aiChat([
{ role: "system", content: "You are helpful." },
{ role: "user", content: "Write a haiku about recursion." }
])
Async example with error handling:
var future = aiChatAsync( "Write a haiku" )
.then( r -> println("AI: " & r) )
.onError( e -> "Error: " & e.getMessage() )
future.get()
aiChatRequest()
Build a ChatRequest for full control and pass it to a service:
chatRequest = aiChatRequest(
"Write a haiku",
{ model: "gpt-4" },
{ provider: "openai", returnFormat: "raw" }
)
response = aiService().invoke( chatRequest )
ChatRequest gives you getters/setters for:
- Messages
- Model
- Provider
- Params
- Headers
- API Key
- Logging settings
- Timeout
And methods for:
- addHeader
- merge defaults
- tool handling
- model and API key fallback
aiMessage()
Fluent message building:
aiMessage()
.system( "You are helpful." )
.user( "Write a haiku" )
.user( "Now tell me the capital of France." )
Supports:
- Adding messages
- Replacing system message
- Getting system/non-system messages
aiService()
Create and reuse provider service objects:
service = aiService( "grok", "myApiKey" )
.defaults( { model: "gpt-3.5", temperature: 0.5 } )
response = service.invoke( aiChatRequest( "Write a haiku" ) )
Implements:
- configure
- invoke
- defaults
- get/set chat URL
aiTool()
Create real-time function-calling tools.
Example:
weatherTool = aiTool(
"get_weather",
"Get current temperature for a city.",
location => {
if ( location contains "Kansas City" ) return "85";
if ( location contains "San Salvador" ) return "90";
return "unknown";
}
).describeLocation( "City and country" )
Use inside a chat:
result = aiChat(
"Which city is warmer: Kansas City or San Salvador?",
{ tools: [ weatherTool ] }
)
Events
The module emits events you can intercept:
| Event | When it Fires | Use Cases |
|---|---|---|
| onAIRequest | Before request is sent | Logging, modification, security |
| onAIResponse | After receiving response | Caching, processing, auditing |
| onAIProviderRequest | When unsupported provider is requested | Registering custom providers |
| onAIProviderCreate | After service object is created | Setup, overrides |
Become a Pioneer or Get a Free Compatibility Report!
BoxLang is growing fast features are expanding, the ecosystem is thriving, and performance is turning heads. But the most exciting part? You can be part of shaping it from the very beginning.
The Pioneer Program is your gateway to early access, unmatched support, and unbeatable value. Here’s what you get:
- Everything in BoxLang+, and more:
- Professional support to get you running smoothly
- A dedicated Slack channel for direct access to our team, solve issues in seconds
- Priority handling for your feature requests and bug fixes
- Migration done with you, not just for you:
- Our engineers work alongside your team to migrate your apps end-to-end
- Guaranteed compatibility, we won’t stop until it works perfectly
- Big savings, no hidden tricks:
- At least 40% off your current licensing costs, locked in early, no surprise charges as you grow
Still Not Convinced?
If you’re unsure how BoxLang will work with your applications, or want clarity before making any decisions, we’ve created a simple, low-risk way to evaluate your path forward:
1. Free BoxLang Compatibility Report
What You Get (Free)
A personalized, expert-driven technical audit designed to help you:
- Determine how compatible your current CFML codebase is with BoxLang
- Identify modernization needs before migrating
- Understand the fastest and safest path to BoxLang adoption
- Receive direct, practical recommendations from the Ortus engineering team
This is a high-touch, hands-on audit — not an automated scan.
Due to demand, we’ve expanded the number of companies we can accept, but availability is still limited.
👉 Register now — it only takes 3 minutes:
https://forms.gle/QSzjmLVsVHQq59mH6
2. 1-Year Free Non-Production License
Test-drive BoxLang Premium features in your own environment, with no pressure.
- Explore advanced capabilities safely
- Experiment and validate assumptions
- Gain confidence before any production commitment
No rush. No lock-in. Just real experience.
Join the BoxLang Community! ⚡️
Stay connected with the latest updates, BoxLang announcements, Into the Box 2026 news, tutorials, tools, and more.
Subscribe to our newsletter for exclusive updates and early access.
Add Your Comment