External AI APIs

CBMKit uses three AI services:

Service Built-in (default) External API
Speech Recognition (STT) whisper.cpp inside the Unreal process Any HTTP speech-to-text API that takes a WAV file and returns JSON
Language Model (LLM) llama.cpp inside the Unreal process Any OpenAI-compatible chat completions API with streaming
Speech Synthesis (TTS) ZONOS3-Mini inside the Unreal process Any HTTP text-to-speech API that takes JSON and returns WAV, raw PCM, or base64 audio in JSON

The built-in services need the local AI install and an NVIDIA GPU (see GETTING_STARTED.md). If your PC has no NVIDIA GPU, or not enough VRAM, set one or more services to an external API. You can mix them, for example a built-in STT with an external LLM and an external TTS.

This guide explains the editor window Tools > CBM > AI Connections…, the related Project Settings, and how CBMKit forms each request.

Related guides:

Labels in bold are written exactly as the editor shows them. Property names in code are the C++ names. The Details panel and Project Settings show them with spaces, for example TTSExternalVoice appears as "TTS External Voice".

1. Quick start

  1. Open Tools > CBM > AI Connections…. The window CBM AI Connections opens.
  2. In the left list, click a service: Speech Recognition (STT), Language Model (LLM), or Speech Synthesis (TTS).
  3. Set Connection to External API.
  4. Choose a Provider. The provider fills in URL and the Advanced values.
  5. Enter the API Key, or ${env:VARIABLE_NAME} to read the key from an environment variable (see section 9).
  6. Enter or check the Model. The LLM providers do not fill in a model. You must type one.
  7. For TTS, enter the Default Voice if the provider needs one.
  8. Click Test Connection. Wait for Test Passed.
  9. Repeat for the other services.
  10. Click Save at the bottom of the window.

A test is not required for saving. Save checks only that the values are complete (see section 7).

2. The AI Connections window

2.1 Layout

Area Content
Left list One entry per service. Each entry shows the service name and its status
Right page The settings of the selected service
Bottom Save button and the save result

Status in the left list:

Status Meaning
Built-in Connection is Built-in
Not Tested Connection is External API, and no test result counts for the current values
Testing A test request is running
Test Passed The last test succeeded with the current values
Test Failed The last test failed with the current values
Companion only Shown for Speech Recognition (STT) when the run type is Broadcast

A test result counts only for the values it was run with. If you change any field or the key after a test, the status returns to Not Tested. Changes that differ only in upper and lower case also count as changes.

2.2 Connection

Each service page starts with Connection:

Value Effect
Built-in The service uses the plugin's built-in AI. The page shows "Uses the plugin's built-in feature instead of an external API."
External API The page shows the fields in section 3

Speech Recognition (STT) can be edited only in the Companion run type. In the Broadcast run type the page shows "Companion only. The Broadcast run type does not use speech recognition." and the fields are disabled. To change the run type, use Tools > CBM (see COMPANION.md and BROADCAST.md).

3. Fields

3.1 Fields on every page

Field Default Meaning
Provider First preset of the list Preset that fills all fields of the page. See section 4
URL From the preset The complete endpoint URL, not a base URL. Must start with http:// or https://. Hint text: https://...
API Key empty The key itself, or ${env:VARIABLE_NAME}. The field hides the text. Empty = no authentication header is sent. Hint text: Key or ${env:VARIABLE_NAME}
Model From the preset Model name sent to the API
Advanced > Auth Header Authorization Name of the HTTP header that carries the key. Empty = no authentication header is sent
Advanced > Key Prefix Bearer (with a trailing space) Text put before the key in the header. The header value is Key Prefix + key. Type the space yourself if the API needs one
Test Connection Sends one real request with the values on the page. See section 6

The Advanced area is collapsed when the window opens. Click Advanced to show it.

The header is sent only when both Auth Header and the resolved key are not empty.

Choosing another Provider replaces every field on the page with the preset values and clears the API Key field. This prevents a key from being sent to a different provider. Enter the key again after you change the provider.

3.2 Language Model (LLM) page

Field Default Meaning
Send Images off On = the model accepts images. Screen, window, game viewport, and webcam images are sent only when this is on. See 5.1
Advanced > Max Tokens Field max_tokens JSON field name for the reply length limit. Some APIs use another name, for example max_completion_tokens
Advanced > Extra Request JSON empty A JSON object merged over the request body. A field with the value null removes that field from the body

Examples for Extra Request JSON:

Value Effect
{"top_p": null} Removes top_p from the request. Used by the Anthropic Claude preset
{"reasoning_effort": "low"} Adds the field reasoning_effort to every request
{"temperature": 0.6} Replaces the temperature value of every request, including the fixed values in section 5.1

3.3 Speech Recognition (STT) page

All STT-only fields are under Advanced.

Field Default Meaning
Request Format multipart multipart = multipart/form-data with the audio as a file part. wav = the WAV file is the whole request body, Content-Type: audio/wav. Hint text: multipart or wav
File Field file multipart only. Form field name of the audio file. The file name is audio.wav
Model Field model multipart only. Form field name of the model. Empty = the model is not sent as a form field
Language Field language multipart only. Form field name of the language code. Empty = the language is not sent as a form field
Result Text Path text Path to the recognized text in the JSON response. Use dots for objects and [n] for array items, for example results.channels[0].alternatives[0].transcript

The URL may contain {{model}} and {{language}}. CBMKit replaces them with the URL-encoded Model and language code. Use this for APIs that take these values as query parameters, and with Request Format wav.

3.4 Speech Synthesis (TTS) page

Field Default Meaning
Default Voice From the preset Voice name used when the speaking character has no TTSExternalVoice. See 5.3
Advanced > Request Body From the preset JSON template of the request body. Must contain {{text}}. See 5.3
Advanced > Response Format wav wav, pcm16, or json_base64. Hint text: wav, pcm16, json_base64
Advanced > Base64 Field audio json_base64 only. Name of the top-level JSON field that holds the base64 audio
Advanced > Sample Rate 24000 pcm16 only, and json_base64 when the decoded audio is not a WAV file. Sample rate of the raw audio in Hz. Must be greater than 0 for pcm16

Response formats:

Response Format Expected response body
wav A WAV file
pcm16 Raw 16-bit signed little-endian mono samples at Sample Rate
json_base64 A JSON object. The field named in Base64 Field holds base64 data. If the decoded data starts with RIFF, it is read as WAV. Otherwise it is read as pcm16 at Sample Rate

The URL may contain {{voice}} and {{model}}. CBMKit replaces them with URL-encoded values.

4. Provider presets

The presets are read from <LocalAIRoot>/providers/external_presets.json. For a Fab (engine) install, the LocalAI root is %LOCALAPPDATA%\CBMKit\LocalAI. The editor copies the plugin's LocalAI files there, so the presets are available without the local AI install. If the file is missing, the Provider list is empty and the Output Log shows No <stt|llm|tts> presets in <path>.

In the Provider list, a preset whose name ends with (local) is shown with (This PC), for example Ollama (This PC).

4.1 LLM presets

Provider URL Other values
OpenAI https://api.openai.com/v1/chat/completions Max Tokens Field = max_completion_tokens
Google Gemini https://generativelanguage.googleapis.com/v1beta/openai/chat/completions
Anthropic Claude https://api.anthropic.com/v1/chat/completions Extra Request JSON = {"top_p": null}
Groq https://api.groq.com/openai/v1/chat/completions
Ollama (This PC) http://127.0.0.1:11434/v1/chat/completions
LM Studio (This PC) http://127.0.0.1:1234/v1/chat/completions
Custom empty Default values of section 3

No LLM preset sets a Model. Type the model name that your provider account can use. Auth Header and Key Prefix stay Authorization and Bearer for all LLM presets.

Ollama and LM Studio run on your own PC. They do not need an API key. They load the model on your own PC, so they do not reduce the load on your PC.

4.2 STT presets

Provider URL Model Other values
OpenAI https://api.openai.com/v1/audio/transcriptions whisper-1
Groq https://api.groq.com/openai/v1/audio/transcriptions whisper-large-v3
ElevenLabs https://api.elevenlabs.io/v1/speech-to-text scribe_v2 Auth Header = xi-api-key, Key Prefix = empty, Model Field = model_id, Language Field = language_code
Deepgram https://api.deepgram.com/v1/listen?model={{model}}&language={{language}}&smart_format=true nova-3 Key Prefix = Token, Request Format = wav, Result Text Path = results.channels[0].alternatives[0].transcript
Custom empty empty Default values of section 3

4.3 TTS presets

Provider URL Model Default Voice Other values
OpenAI https://api.openai.com/v1/audio/speech gpt-4o-mini-tts coral Request Body = {"model": {{model}}, "voice": {{voice}}, "input": {{text}}, "speed": {{speed}}, "response_format": "wav"}, Response Format = wav
ElevenLabs https://api.elevenlabs.io/v1/text-to-speech/{{voice}}?output_format=pcm_24000 eleven_multilingual_v2 empty Auth Header = xi-api-key, Key Prefix = empty, Request Body = {"text": {{text}}, "model_id": {{model}}}, Response Format = pcm16, Sample Rate = 24000
Custom empty empty empty Request Body = {"text": {{text}}, "voice": {{voice}}, "model": {{model}}, "format": "wav"}, Response Format = wav

For ElevenLabs, enter a voice ID from your ElevenLabs account in Default Voice. The preset has none.

4.4 Your own presets

You can add presets to external_presets.json. The file has three arrays: stt, llm, and tts. Each entry is an object with the field names below. Preset is the name in the list and is required. Fields you leave out keep the defaults of section 3.

JSON field Window field
Preset Provider
Url URL
Model Model
AuthHeader Auth Header
AuthPrefix Key Prefix
MaxTokensField Max Tokens Field
ExtraBody Extra Request JSON (a JSON object written as a string)
bSendImages Send Images
RequestFormat Request Format
FileField File Field
ModelField Model Field
LanguageField Language Field
TextPath Result Text Path
Voice Default Voice
Body Request Body
ResponseFormat Response Format
ResponseField Base64 Field
SampleRate Sample Rate

Do not put API keys in this file.

For a Fab (engine) install, edit the copy in %LOCALAPPDATA%\CBMKit\LocalAI\providers. A plugin update does not replace a file you changed. The Output Log lists the kept file when the plugin has a newer version; merge new presets from the plugin's ThirdParty/LocalAI/providers by hand.

5. How the requests are formed

5.1 LLM

CBMKit sends an OpenAI-compatible chat completions request.

Part Value
Method and URL POST to URL as entered
Headers Content-Type: application/json; charset=utf-8, Accept: text/event-stream, and the authentication header
model Model
messages Array of { "role", "content" }. Roles are system, user, and assistant
stream true
temperature See the table below
top_p See the table below
Max Tokens Field See the table below
Extra Request JSON Merged last

The response is read as server-sent events. Each data: line is a JSON object, and the text is taken from choices[0].delta.content. data: [DONE] ends the reply. A non-streamed JSON response with choices[0].message.content is also accepted. The request times out after 120 seconds, or after 60 seconds without received data.

Every LLM job of CBMKit uses the same external LLM:

Job temperature top_p Max tokens
Character replies Temperature setting (default 0.8) 0.95 MaxTokens setting (default 200)
Topic planner (Broadcast topics) 0.4 0.9 TopicPlannerMaxTokens setting (default 200)
Memory extraction 0.2 0.9 256

Temperature and MaxTokens are in Project Settings > Plugins > CBM, category LLM. The topic planner and memory extraction are turned on and off with bTopicPlanner and bEnableMemory. Each request also contains the conversation history, up to MaxHistoryTurns turns. All these requests count toward your provider usage and cost.

Images. When Send Images is on and a turn has an image (from VisionSource or from an input that carries its own image), the last user message is sent as a content array: one part per image with "type": "image_url" and a data:image/jpeg;base64,... or data:image/png;base64,... URL, followed by a "type": "text" part. When Send Images is off, images are dropped and the Output Log shows a warning.

If the API refuses a request with an image (HTTP 400, 413, 415, or 422) before any reply text arrives, CBMKit sends the same turn again without the image. If that retry succeeds, CBMKit stops sending images to this URL and model until the game restarts, and reports "External LLM refused the image; this model continues without images."

5.2 STT

STT runs only in the Companion run type. After the voice detector ends an utterance, CBMKit sends one request per utterance.

Part Value
Audio WAV, 16 kHz, mono, 16-bit PCM
Method and URL POST to URL, with {{model}} and {{language}} replaced
Request Format multipart Form fields: Model Field = Model, Language Field = language code, File Field = audio.wav (audio/wav)
Request Format wav The WAV file is the body. Model and language go only through the URL placeholders
Language code STTLanguage setting. Empty = the character language. See COMPANION.md
Timeout 30 seconds
Response JSON. The text is read at Result Text Path

5.3 TTS

CBMKit splits each reply into sentences and sends one request per sentence. Up to 2 requests run at the same time. Audio plays in sentence order.

Part Value
Method and URL POST to URL, with {{voice}} and {{model}} replaced (URL-encoded)
Headers Content-Type: application/json and the authentication header
Body Request Body with the placeholders below replaced
Timeout 30 seconds

Placeholders in Request Body:

Placeholder Replaced with
{{text}} The sentence to speak. Required
{{voice}} The character's TTSExternalVoice. Empty = Default Voice
{{model}} Model
{{emotion}} The emotion of the sentence, for example normal, happy, sad, angry, surprised, embarrassed
{{speed}} Speech speed as a number. Currently always 1.0

In Request Body, {{text}}, {{voice}}, {{model}}, and {{emotion}} are replaced with quoted JSON strings. Write them without quotes: "input": {{text}}, not "input": "{{text}}". {{speed}} is replaced with a bare number.

${env:NAME} inside URL or Request Body is replaced with the value of the environment variable NAME.

Emotion names are sent as the character uses them. If your TTS API uses other style names, map them per character with TTSEmotionOverrides, for example embarrassed → shy (see CHARACTERS.md).

Per-character voice:

Where Field Effect
Character definition TTSExternalVoice (category Voice) Voice name for the external TTS API. Empty = Default Voice
Room Setup (Broadcast) External TTS Voice Written to TTSExternalVoice of the slot's character definition. Empty = the definition keeps its value

When TTS is external, TTSVoice and TTSCharacter are not used. When TTS is built-in, TTSExternalVoice is not used.

6. Test Connection

Test Connection sends one real request with the values currently on the page, including values you have not saved. It may count toward your provider usage.

Service Test request Text after "Success:"
LLM, Send Images off One user message "Reply with one short word.", max tokens 16 The model reply, up to 60 characters
LLM, Send Images on One user message with a 64 × 64 red PNG image: "What color is this image? Reply with one word." "Sent a red image. Model reply: {reply}"
STT 1 second of silence The recognized text, often empty
TTS "Hello." (or "안녕하세요." when the character language is Korean), emotion normal Audio length and sample rate, for example 1.2 s, 24000 Hz

With Send Images on, check the reply. A model that ignores images without an error does not answer "red". If the image request is refused (HTTP 400, 413, 415, or 422), the test sends the text request. If the text request succeeds, the test fails with "The text request succeeded, but the request with an image was refused. If this model does not support images, turn off image sending."

Test text next to the button:

Text Meaning
Testing... The request is running. The button is disabled
Success: {detail} The request succeeded. The left list shows Test Passed
Failed: {detail} The request failed or the values are incomplete. The left list shows Test Failed

Failure messages:

Message Cause
Could not reach the server, or the response timed out. Check the URL and network. No HTTP response
The server rejected the request. Check the model name and Advanced settings. (HTTP 400 or 422) Wrong model name or request fields
The API key is invalid. Check the key. (HTTP 401) Wrong key, wrong Auth Header or Key Prefix, or an empty environment variable
Check the credits or billing status of your provider account. (HTTP 402) Billing
This key has no permission. Check the key and model permissions in your provider account. (HTTP 403) Permissions
URL or model not found. Check the URL and model name. (HTTP 404) Wrong URL or model
The server response timed out. Try again later. (HTTP 408 or 504) Server timeout
The server does not accept the size or format of this request. Check the Advanced settings. (HTTP 413 or 415) Request size or format
Usage limit exceeded or too many requests. Try again later or check your provider plan. (HTTP 429) Rate limit or quota
Provider server error. Try again later. (HTTP 5xx) Provider error
The server returned an error. Other HTTP error
No recognized text in the response. Check the result text path in Advanced. STT response is not JSON, or Result Text Path does not point to a string
No audio data in the response. Check the response format and base64 field in Advanced. TTS json_base64 response has no Base64 Field
Could not process the response. Check the response format in Advanced. Other response errors, for example a TTS response that is not a valid WAV file
Could not start the request. Check the Output Log. The request could not be created

When the server sent a reply body, the message also shows "Server reply: {first 200 characters}".

7. Save

Save applies all three pages at once.

  1. Save checks each service whose Connection is External API. If a value is missing or invalid, nothing is saved. The window opens the page with the problem and shows "{service}: {problem}".
  2. Save writes the settings and the keys.
  3. Save restarts each running service whose connection, settings, or key changed. You do not need to restart the editor.

Checks done by Save (and by Test Connection):

Service Message
All URL must start with http:// or https://.
LLM Enter a model name.
LLM Enter the max tokens field in Advanced.
LLM The extra request JSON in Advanced is not a JSON object.
STT The request format in Advanced must be multipart or wav.
STT Enter the file field in Advanced. (Request Format multipart only)
STT Enter the result text path in Advanced.
TTS Enter the request body in Advanced.
TTS The request body in Advanced must contain {{text}}.
TTS The response format in Advanced must be wav, pcm16 or json_base64.
TTS The sample rate in Advanced must be greater than 0. (Response Format pcm16 only)

Save does not check the API key. A missing key shows up as HTTP 401 in the test or in the game.

7.1 Where values are saved

What File Section or field
Connection of each service <Project>/Config/DefaultGame.ini [/Script/CBMKit.CBMSettings], STTBackend, LLMBackend, TTSBackend
All other fields (no keys) <Project>/Config/DefaultGame.ini [/Script/CBMKit.CBMSettings], ExternalSTT, ExternalLLM, ExternalTTS
API Key fields %LOCALAPPDATA%\CBMKit\api_keys.json JSON fields stt, llm, tts

After a successful save, the window shows "Saved. Key file: {full path of api_keys.json}". If a file could not be written, it shows "Could not save. Check the Output Log."

The key file is outside the project folder. It is not committed with the project and not packaged into a game. It holds the text exactly as you typed it: the key itself in plain text, or ${env:VARIABLE_NAME}. Clearing the API Key field and saving removes that service's entry from the file.

Selecting Built-in and saving keeps the external values of that service in DefaultGame.ini. Selecting External API again restores them.

These are in Project Settings > Plugins > CBM.

Category Setting Default Meaning
Services STTBackend InProcess External = the window's External API. The window sets this value
Services LLMBackend InProcess External = the window's External API. The window sets this value
TTS TTSBackend InProcess External = the window's External API. Provider = a registered TTS provider (8.1)
LLM Temperature 0.8 temperature of character replies, also for the external LLM
LLM MaxTokens 200 Reply length limit, sent in Max Tokens Field
STT STTLanguage empty Language code sent to STT. Empty = character language
Vision VisionSource None Images sent with turns. With an external LLM, needs Send Images

The window writes only STTBackend, LLMBackend, TTSBackend, ExternalSTT, ExternalLLM, and ExternalTTS. The window shows Built-in for any value other than External. Saving the window changes a backend value only when you switch between Built-in and External API.

STTBackend and LLMBackend also have the value HttpServer. It and the built-in fallback to local servers on ports 18010 (STT) and 18020 (LLM) belong to the local AI install. They are not external APIs and are not covered here.

8.1 Generic HTTP TTS provider

This is a second way to use an HTTP TTS API, configured with a JSON file instead of the window. Use the window (TTSBackend = External) unless you need a feature that only this file has, for example emotion_map or other HTTP methods.

Setting Default Meaning
TTSBackend InProcess Set to Provider
TTSProviderName GenericHttp Name of the registered provider. GenericHttp is the provider for this file
TTSProviderConfig empty Path of the JSON file. Empty = <LocalAIRoot>/providers/generic_http.json. A relative path resolves against the project folder
bTTSProviderFallback on On = if the provider is not usable, CBMKit uses the built-in TTS (needs the local AI install). Off = TTS fails and replies are text only

Start from <LocalAIRoot>/providers/generic_http.example.json. Copy it to generic_http.json and set "enabled": true.

JSON field Meaning
enabled Must be true. false = the provider is not usable
url Endpoint. May contain placeholders, values are URL-encoded
method HTTP method. Default POST
headers Object of header names and values. Values may contain placeholders and ${env:NAME}
body JSON template with {{text}}, {{voice}}, {{model}}, {{emotion}}, {{speed}} (same rules as 5.3)
model Value of {{model}}
voice Value of {{voice}} when the request has no voice
response format (wav, pcm16, json_base64), field (base64 field), sample_rate
emotion_map Object that maps CBMKit emotion names to the API's style names. Unmapped names are sent as they are
voices List of { "name", "emotions", "default_emotion" }
timeout Seconds. Default 30
max_concurrent Requests at the same time. Default 2 in the example

Put keys in headers as ${env:NAME}, for example "Authorization": "Bearer ${env:CBMKIT_TTS_API_KEY}". Never write a key into this file.

With TTSBackend = Provider, {{voice}} receives the character's TTSExternalVoice. Empty = the voice value in this file.

9. API key security

10. Running without the local AI

If all three services are set to External API:

If only some services are external, the local AI install is still needed for the others. A service set to External API does not load its local model. The model files check skips external services.

VRAM of the built-in services, from GETTING_STARTED.md:

Built-in part VRAM (about)
All three, rtx5070 profile, with image input 7 GB
All three, rtx4090 profile 11 GB
TTS on the GPU 1.3 GB (0 with bTTSOnGPU off)
Image input model, rtx5070 1.15 GB

Moving the LLM to an external API removes the largest part, because the LLM and its image input model are the largest models. Moving TTS removes about 1.3 GB.

The prompt files (persona, rules, modes) are still read from the plugin and the LocalAI root. You can edit them with Tools > CBM > Prompt Editor… as with the built-in LLM.

11. Packaged games

12. Checking the connection in the editor