The Custom provider enables you to integrate any LLM API endpoint that isn’t already supported by writing a simple Rhai script. This is perfect for proprietary APIs, custom deployments, or non-standard endpoints.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/circuitbreakerlabs/cli/llms.txt
Use this file to discover all available pages before exploring further.
How It Works
The Custom provider uses a Rhai script to translate between Circuit Breaker Labs’ internal message format and your custom API’s request/response schema.CBL sends messages to your script
Circuit Breaker Labs provides conversation history as an array of messages with
role and content fields.Your script builds the request
The
build_request() function transforms messages into your API’s expected format.Configuration Options
Endpoint URL to POST requests to.Example:
https://api.example.com/v1/chat/completionsPath to the Rhai script file that defines request/response translation.Example:
--script ./providers/my_custom_api.rhaiWriting a Custom Script
Your Rhai script must implement two functions:build_request(messages)
Transforms the conversation history into your API’s request format. Parameters:messages(array): Array of message objects, each with:role(string): Either"system","user", or"assistant"content(string): The message content
parse_response(body)
Extracts the assistant’s response from your API’s response. Parameters:body(dynamic): The full deserialized JSON response from your API
Example Scripts
OpenAI-Compatible API
Ollama API
Custom API with Authentication
Anthropic Claude API
Google Gemini API
Complete Usage Example
Rhai Language Basics
Rhai is a simple scripting language with JavaScript-like syntax:Creating Objects (Maps)
Accessing Fields
Arrays
Loops
String Conversion
For complete Rhai documentation, visit rhai.rs/book.
Example Scripts Repository
Circuit Breaker Labs provides example scripts in the repository:openai_completions.rhai- OpenAI chat completions APIollama_chat.rhai- Ollama chat APIopenai_responses.rhai- OpenAI with response formattingollama_completions.rhai- Ollama completions endpoint
Debugging Your Script
Rhai scripts can useprint() and debug() functions for logging:
Authentication
For APIs requiring authentication, you have several options:1. Include in Request Body
2. Use HTTP Headers
Set authentication headers using environment variables or CBL configuration. The Custom provider automatically includes headers from the CBL context.3. URL Parameters
Error Handling
If your script encounters an error, CBL will report it with the error location:- Accessing non-existent fields: Check the API response structure
- Type mismatches: Ensure proper type conversions with
.to_string() - Missing return values: Both functions must return a value
Tips
Related Resources
Rhai Language Book
Complete Rhai scripting language documentation
Example Scripts
Ready-to-use provider scripts for common APIs