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

12 Days of BoxLang - Day 12: BoxLang Pionner Program

12 Days of BoxLang - Day 12: BoxLang Pionner Program

Be the first to shape the future of the JVM’s newest language and get a FREE BoxLang Compatibility Audit.

As we close out our 12 Days of BoxLang Christmas, we’re ending with something truly special — something built for early adopters, innovators, and teams who want to modernize confidently as we move into 2026.

Today, we’re excited to officially announce the BoxLang Pioneer Program.

This program is your opportunity to work closely with the BoxLang team, influence the roadmap, test new capabilities early, and prepare your applications for the next generation of JVM development.

Maria Jose Herrera
Maria Jose Herrera
December 23, 2025
Day 11 BoxLang SOAP: Enterprise Integrations Made Simple! 🎄

Day 11 BoxLang SOAP: Enterprise Integrations Made Simple! 🎄

As we head toward 2026, modern platforms still need to speak the language of the enterprise.

And in many organizations, that language is still SOAP.

With BoxLang 1.8.0, SOAP web services are no longer something you “tolerate” — they’re something you can work with fluently, safely, and cleanly.

Today, we’re exploring BoxLang’s native SOAP client, designed to make consuming SOAP 1.1 and SOAP 1.2 services feel natural, modern, and predictable.

Maria Jose Herrera
Maria Jose Herrera
December 22, 2025
12 Days of BoxLang - Day 10 BoxLang Miniserver 🎄

12 Days of BoxLang - Day 10 BoxLang Miniserver 🎄

Day 10: BoxLang MiniServer: Lightning-Fast Web Apps, Simplified

As we head into 2026, speed, simplicity, and flexibility matter more than ever. That’s why today’s ...

Maria Jose Herrera
Maria Jose Herrera
December 20, 2025