Blog

12 Days of BoxLang - Day 6: BoxLang AI

Maria Jose Herrera December 16, 2025

Spread the word

Maria Jose Herrera

December 16, 2025

Spread the word


Share your thoughts

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

ProviderTools
ClaudeYes
DeepSeekYes
GeminiComing Soon
GrokYes
OpenAIYes
PerplexityYes

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:

EventWhen it FiresUse Cases
onAIRequestBefore request is sentLogging, modification, security
onAIResponseAfter receiving responseCaching, processing, auditing
onAIProviderRequestWhen unsupported provider is requestedRegistering custom providers
onAIProviderCreateAfter service object is createdSetup, 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:

  1. 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
  2. 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
  3. Big savings, no hidden tricks:
    • At least 40% off your current licensing costs, locked in early, no surprise charges as you grow

Request More Info


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.

Contact Us


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.

Follow Us

Add Your Comment

Recent Entries

Ortus & BoxLang Jan Recap 2026

Ortus & BoxLang Jan Recap 2026

January kicked off with strong momentum across the Ortus Solutions ecosystem, bringing key product releases, major improvements to CommandBox and BoxLang, new cloud-focused learning resources, and exciting announcements for upcoming events.

Victor Campos
Victor Campos
February 02, 2026
BoxLang AI: The Foundation for Real-World AI Systems!

BoxLang AI: The Foundation for Real-World AI Systems!

BoxLang AI: From AI Experiments to Real-World Systems!

Why we built BoxLang AI?

AI is everywhere. New models, new tools, new announcements every week. But for most teams, the real challenge isn’t choosing ...

Victor Campos
Victor Campos
January 30, 2026
Speaker Featuring - Round 1

Speaker Featuring - Round 1

Every conference is more than the talks we see on stage it’s also the story of the people who make it possible.

With the first round of Into the Box 2026 sessions and workshops now live, we’re excited to introduce some of the speakers who will be joining us this year. These community members, practitioners, and Ortus team experts bring decades of real-world experience across CFML, BoxLang, JVM modernization, testing, AI, and cloud-native development.

Victor Campos
Victor Campos
January 26, 2026
// Remove it when the Silicon theme is implemented document.querySelector('.career-job-card').addEventListener('click', function() { const details = this.querySelector('.career-job-details'); details.style.display = details.style.display === 'block' ? 'none' : 'block'; });