Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Live calls: add a custom OpenAI-compatible endpoint as a provider

Bugfixer 2759d576b9599
diff --git a/docs/verification/live-calls.md b/docs/verification/live-calls.md
index 2a76dc2615..b5f942249d 100644
--- a/docs/verification/live-calls.md
+++ b/docs/verification/live-calls.md
@@ -119,6 +119,34 @@ the full server with a made-up key and its `fetch` stubbed.
`server/hosted-access.test.ts` does it for a shared workspace, with no key saved,
so a caller who gets through stops at the setup prompt.
+## A custom endpoint as the Live provider
+
+With `live.provider: "custom"` (`OMB_LIVE_PROVIDER=custom`) a call goes to a
+server the person names that speaks OpenAI's GPT-Live API, such as their own
+gateway: `POST {endpoint}/live/sessions` with `live.customModel`
+(`OMB_CUSTOM_LIVE_MODEL`, default `gpt-live-1`) as `session.model`, and the
+sideband attaches to `wss://{endpoint}/live/sessions/{id}/attach`. The request
+is OpenAI's own: the key goes as a bearer token and `session.client` is sent.
+`live.customEndpoint` (`OMB_CUSTOM_LIVE_ENDPOINT`) is read by
+`customLiveApiBase` in `server/live-call.ts`: `https` on any host, or `http`
+only on loopback (`127.0.0.1`, `localhost`, `[::1]`); no user name, password,
+query or fragment; a bare host or one ending in `/live/sessions` becomes
+`…/v1`. `PATCH /api/live/settings` refuses any other address, and the session
+request refuses a redirect.
+
+The key is only `live.key`, tied to `custom:<host>` the same way an Azure key is
+tied to its host; the OpenAI API key is never sent to a custom endpoint. Without
+the key, or with a missing or invalid endpoint, `POST /api/live/session` answers
+`409` with `needsKey` before anything leaves the harness.
+
+Nothing checks that a custom endpoint keeps to `LIVE_DATA_CHANNEL`, so its calls
+have Azure's limit: only an admin, or the owner of a single-owner server, may
+start one (`LIVE_CUSTOM_REFUSAL` in `server/live-access.ts`).
+
+```sh
+pnpm exec vitest run server/live-custom.test.ts server/live-call-controller.test.ts server/routes/live.test.ts
+```
+
## Fish Audio Live 3 as the Live provider
With `live.provider: "fish"` (`OMB_LIVE_PROVIDER=fish`) a call uses the Fish
diff --git a/packages/phone-protocol/src/live-call-wire.ts b/packages/phone-protocol/src/live-call-wire.ts
index f9aadafd8d..29d60eae99 100644
--- a/packages/phone-protocol/src/live-call-wire.ts
+++ b/packages/phone-protocol/src/live-call-wire.ts
@@ -48,8 +48,9 @@ export interface LiveCallRecord {
/** Who runs a Live call's voice session: OpenAI itself, a GPT-Live deployment on the user's own Azure OpenAI / Foundry
* resource, a Fish Audio Live 3 agent the harness sets up on the person's Fish Audio account, whose session the client joins with Fish's SDK,
* the Gemini Live API on the person's Gemini key, which the client reaches with a single-use token the harness creates, or an
- * ElevenLabs agent the harness sets up on the person's ElevenLabs account, which the client reaches with a signed URL. */
-export type LiveProvider = "openai" | "azure" | "fish" | "gemini" | "elevenlabs";
+ * ElevenLabs agent the harness sets up on the person's ElevenLabs account, which the client reaches with a signed URL, or
+ * "custom": an OpenAI-compatible server the person names (a gateway that serves the GPT-Live API), reached like OpenAI. */
+export type LiveProvider = "openai" | "azure" | "fish" | "gemini" | "elevenlabs" | "custom";
/** `live`: the key saved for Live calls only; `openai`: the OpenAI API key from Settings → API keys, used when there is no `live` key;
* `fishAudio`: the Fish Audio key from Settings → API keys, the only key a Fish Audio call uses;
@@ -62,13 +63,17 @@ export interface LiveSettings {
/** A Live call has everything it needs: a key (`keySource` says which; never the key itself), and for Azure a valid endpoint and deployment. */
configured: boolean;
keySource?: LiveKeySource;
- /** Absent means "openai". With "azure" only the `live` key is used, with "fish" only the Fish Audio key, with "gemini" only the
+ /** Absent means "openai". With "azure" or "custom" only the `live` key is used, with "fish" only the Fish Audio key, with "gemini" only the
* Gemini key and with "elevenlabs" only the ElevenLabs key, never the OpenAI API key. */
provider?: LiveProvider;
/** The Azure resource endpoint as saved, e.g. `https://my-resource.openai.azure.com`. Not a secret. */
azureEndpoint?: string;
/** The Azure deployment of gpt-live-1; empty means "gpt-live-1". */
azureDeployment?: string;
+ /** The custom endpoint as saved, e.g. `https://gateway.example.com/v1`. Not a secret. */
+ customEndpoint?: string;
+ /** The model a custom endpoint's calls use; empty means "gpt-live-1". */
+ customModel?: string;
voice: string;
/** The Gemini Live voice for "gemini" calls; absent means Gemini's default. */
geminiVoice?: string;
diff --git a/server/bot-box/env.test.ts b/server/bot-box/env.test.ts
index 35d65cf6a2..d81fc571c3 100644
--- a/server/bot-box/env.test.ts
+++ b/server/bot-box/env.test.ts
@@ -32,7 +32,7 @@ const SERVER_ONLY_OMB: ReadonlySet<string> = new Set([
"OMB_COMPANION_TAILNET_NAME", "OMB_COMPOSIO_API", "OMB_COMPOSIO_BROKER", "OMB_COMPOSIO_BROKER_TOKEN",
"OMB_COMPOSIO_BROKER_URL", "OMB_COMPOSIO_TOOLKITS_API", "OMB_COMPUTER_CALL_ACT_WITHIN_MS",
"OMB_COMPUTER_CALL_WAIT_MS", "OMB_COMPUTER_WAIT_MAX_MS", "OMB_CONTROL_PLANE_URL", "OMB_CONTROL_PORT",
- "OMB_CREDENTIAL_STORE", "OMB_CUSTOM_DECIDER_KEY", "OMB_CUSTOM_IMAGE_KEY", "OMB_DATA_DIR", "OMB_DECISION_RETENTION_DAYS",
+ "OMB_CREDENTIAL_STORE", "OMB_CUSTOM_DECIDER_KEY", "OMB_CUSTOM_IMAGE_KEY", "OMB_CUSTOM_LIVE_ENDPOINT", "OMB_CUSTOM_LIVE_MODEL", "OMB_DATA_DIR", "OMB_DECISION_RETENTION_DAYS",
"OMB_DEEPSEEK_API_KEY", "OMB_DESKTOP_LAUNCH_ID", "OMB_DESKTOP_PARENT", "OMB_DEVS_STATUS_MS",
"OMB_DEV_TRUST_LOCAL_BROWSER", "OMB_DISABLE_ANNOUNCEMENTS", "OMB_DISABLE_MODEL_CATALOG_FETCH", "OMB_DISABLE_MODEL_MANIFEST_FETCH", "OMB_DUCKDB_DIR", "OMB_DUCKDB_MAX_TEMP_SIZE",
"OMB_DUCKDB_MEMORY_LIMIT", "OMB_ELEVENLABS_API", "OMB_ENTERPRISE_DIR", "OMB_ENVIRONMENT_LABEL", "OMB_EOF",
diff --git a/server/live-access.ts b/server/live-access.ts
index c983d510b3..d4004581dc 100644
--- a/server/live-access.ts
+++ b/server/live-access.ts
@@ -1,9 +1,10 @@
-// Who may hold a Live call through Azure OpenAI, Fish Audio, Gemini or ElevenLabs. LIVE_DATA_CHANNEL in live-call.ts says why Azure is
+// Who may hold a Live call through Azure OpenAI, a custom endpoint, Fish Audio, Gemini or ElevenLabs. LIVE_DATA_CHANNEL in live-call.ts says why Azure is
// limited; on the relayed providers the harness hears the call only through its client's own reports (FishRelay in live-fish.ts).
import type { AppConfig } from "./config.ts";
import type { RequestAuth } from "./request-auth.ts";
export const LIVE_AZURE_REFUSAL = "Live calls here go through Azure OpenAI, so only an admin or the owner of this server can start one. Ask an admin if you need a call.";
+export const LIVE_CUSTOM_REFUSAL = "Live calls here go through a custom endpoint, so only an admin or the owner of this server can start one. Ask an admin if you need a call.";
export const LIVE_FISH_REFUSAL = "Live calls here go through Fish Audio, so only an admin or the owner of this server can start one. Ask an admin if you need a call.";
export const LIVE_GEMINI_REFUSAL = "Live calls here go through Gemini, so only an admin or the owner of this server can start one. Ask an admin if you need a call.";
export const LIVE_ELEVENLABS_REFUSAL = "Live calls here go through ElevenLabs, so only an admin or the owner of this server can start one. Ask an admin if you need a call.";
@@ -40,5 +41,5 @@ export function liveScopeRefusal(cfg: Pick<AppConfig, "live">, method: string, p
if (method.toUpperCase() !== "POST" || path !== "/api/live/session") return null;
const provider = cfg.live?.provider;
return provider === "azure" ? LIVE_AZURE_REFUSAL : provider === "fish" ? LIVE_FISH_REFUSAL : provider === "gemini" ? LIVE_GEMINI_REFUSAL
- : provider === "elevenlabs" ? LIVE_ELEVENLABS_REFUSAL : null;
+ : provider === "elevenlabs" ? LIVE_ELEVENLABS_REFUSAL : provider === "custom" ? LIVE_CUSTOM_REFUSAL : null;
}
diff --git a/server/live-call-controller.test.ts b/server/live-call-controller.test.ts
index 41abac4f29..e3f35d1c77 100644
--- a/server/live-call-controller.test.ts
+++ b/server/live-call-controller.test.ts
@@ -5,6 +5,7 @@ import {
LIVE_FISH_NEEDS_APP, LIVE_ELEVENLABS_NEEDS_APP, LIVE_GEMINI_NEEDS_APP, LiveCallBusyError, LiveCallController, LiveCallSignedOutError, type LiveActivity, type LiveCallDeps, type LiveSocket,
} from "./live-call-controller.ts";
import { LIVE_COPY } from "../shared/live-approval.ts";
+import { LIVE_CUSTOM_REFUSAL } from "./live-access.ts";
import { LIVE_NEEDS_AZURE, LIVE_NEEDS_KEY, LiveSessionError, type LiveEndpoint } from "./live-call.ts";
import { FishRelays, FISH_AGENT_VOICE } from "./live-fish.ts";
import type { LiveElevenLabsSession, LiveFishSessionToken, LiveGeminiSession } from "../shared/wire.ts";
@@ -192,6 +193,28 @@ describe("LiveCallController lifecycle", () => {
});
+ describe("with a custom endpoint chosen", () => {
+ const CUSTOM: LiveEndpoint = { provider: "custom", apiBase: "https://gateway.example.com/v1", model: "gpt-live-1" };
+ const member: RequestAuth = { kind: "loopback", scopes: ["client"], trust: "service" };
+ const custom = (overrides: Partial<LiveCallDeps> = {}) => {
+ const t = setup(overrides);
+ t.settings.endpoint = CUSTOM;
+ t.settings.provider = "custom";
+ return t;
+ };
+
+ it("holds the call to Azure's limit, in the custom endpoint's own words, and starts it like OpenAI when allowed", async () => {
+ const refused = custom({ azureRefusal: () => "Azure's words" });
+ await expect(refused.controller.start({ auth: member, ...BOT, client: "web", sdp: "a" })).rejects.toMatchObject({ status: 403, message: LIVE_CUSTOM_REFUSAL });
+ expect(refused.deps.createSession).not.toHaveBeenCalled();
+ const t = custom();
+ await t.controller.start({ auth: owner, ...BOT, client: "web", sdp: "a" });
+ expect(t.deps.azureRefusal).toHaveBeenCalledWith(owner);
+ expect(t.deps.fishRefusal).not.toHaveBeenCalled();
+ expect(t.deps.createSession).toHaveBeenCalledWith(expect.objectContaining({ endpoint: CUSTOM }));
+ });
+ });
+
describe("with Fish Audio chosen", () => {
const FISH: LiveEndpoint = { provider: "fish", apiBase: "https://api.fish.audio/v1/agent", model: "agent_1" };
const REFUSED = "only an admin, in these words";
diff --git a/server/live-call-controller.ts b/server/live-call-controller.ts
index 32d6c72d4a..3d67c6ebd4 100644
--- a/server/live-call-controller.ts
+++ b/server/live-call-controller.ts
@@ -9,6 +9,7 @@ import { signInWaits } from "../shared/sign-in-request.ts";
import type { LiveCallRecord, LiveCallState, LiveClient, LiveElevenLabsTransport, LiveEndReason, LiveFishTransport, LiveGeminiTransport, LiveProvider } from "../shared/wire.ts";
import { FISH_AGENT_VOICE } from "./live-fish.ts";
import { LIVE_NEEDS_KEY, liveAuthHeaders, liveCallSummaryLine, liveProviderName, LiveSessionError, liveVoice, spokenHangUp, type LiveEndpoint } from "./live-call.ts";
+import { LIVE_CUSTOM_REFUSAL } from "./live-access.ts";
import type { RequestAuth } from "./request-auth.ts";
import type { Message, StoreChange } from "./store.ts";
@@ -184,17 +185,20 @@ export class LiveCallController {
// First: someone refused here is not told about a running call, or sent to set Azure or a relayed service up.
// The chosen relayed service comes before a key's endpoint, so its refusal and its mismatch check apply.
const relayedChoice = relayedProvider(settings.provider);
+ // A custom endpoint is held to Azure's limit (LIVE_DATA_CHANNEL), with its own words.
const limited = settings.provider === "azure" || settings.endpoint?.provider === "azure" ? "azure"
+ : settings.provider === "custom" || settings.endpoint?.provider === "custom" ? "custom"
: relayedChoice ?? relayedProvider(settings.endpoint?.provider);
if (limited) {
- const refusal = limited === "azure" ? this.deps.azureRefusal(input.auth) : limited === "fish" ? this.deps.fishRefusal(input.auth)
+ const refusal = limited === "azure" ? this.deps.azureRefusal(input.auth) : limited === "custom" ? this.deps.azureRefusal(input.auth) && LIVE_CUSTOM_REFUSAL
+ : limited === "fish" ? this.deps.fishRefusal(input.auth)
: limited === "gemini" ? this.deps.geminiRefusal(input.auth) : this.deps.elevenlabsRefusal(input.auth);
if (refusal) {
this.deps.log(`[live] call refused bot=${input.botId} client=${input.client} provider=${limited}`);
throw new LiveSessionError(refusal, 403);
}
}
- const relayed = limited === "azure" ? null : limited;
+ const relayed = limited === "azure" || limited === "custom" ? null : limited;
if (relayed && (input.client === "ios" || input.client === "android")) throw new LiveSessionError(relayed === "fish" ? LIVE_FISH_NEEDS_APP : relayed === "gemini" ? LIVE_GEMINI_NEEDS_APP : LIVE_ELEVENLABS_NEEDS_APP, 400);
if (!relayed && !input.sdp) throw new LiveSessionError("The call request was not valid.", 400);
if (this.call && this.call.state.status !== "ended") throw new LiveCallBusyError({ ...this.call.state });
diff --git a/server/live-call.ts b/server/live-call.ts
index 40dcb66277..fd29808eeb 100644
--- a/server/live-call.ts
+++ b/server/live-call.ts
@@ -11,6 +11,7 @@ export const LIVE_NEEDS_KEY = "Live calls use your own OpenAI key. Add it in Set
export const LIVE_NEEDS_AZURE = "Live calls through Azure OpenAI need the resource endpoint, the GPT-Live deployment name and its key. Add them in Call settings.";
export const LIVE_NEEDS_FISH = "Live calls through Fish Audio use your Fish Audio API key. Add it in Settings → API keys.";
export const LIVE_NEEDS_GEMINI = "Live calls through Gemini use your Gemini API key. Add it in Settings → API keys.";
+export const LIVE_NEEDS_CUSTOM = "Live calls through a custom endpoint need its address and its own key. Add them in Call settings.";
export const LIVE_NEEDS_ELEVENLABS = "Live calls through ElevenLabs use your ElevenLabs API key. Add it in Settings → API keys.";
/** The client's data channel is untrusted: it may only hang up; every append goes over the sideband.
@@ -18,7 +19,8 @@ export const LIVE_NEEDS_ELEVENLABS = "Live calls through ElevenLabs use your Ele
* Azure's default events. Read that as: the caller may send session or item events and receive events holding the bot's
* instructions (not checked against Azure itself). So an Azure call is only for an admin or the owner of a single-owner
* server, never another team Member, a shared workspace's non-admin or anyone else: azureLiveCallRefusal in live-access.ts,
- * asked by LiveCallController.start. */
+ * asked by LiveCallController.start. A custom endpoint gets the list, but nothing here checks that it keeps to it, so its
+ * calls have the same limit. */
export const LIVE_DATA_CHANNEL = {
allowed_client_events: ["session.close"],
allowed_server_events: [
@@ -41,6 +43,7 @@ const AZURE_HOST_SUFFIXES = [
".azure-api.net",
] as const;
const AZURE_DEPLOYMENT = /^[A-Za-z0-9][\w.-]{0,63}$/;
+const CUSTOM_MODEL = /^[A-Za-z0-9][\w.:/-]{0,63}$/;
/** Where a Live call's session is created and its sideband attached. Never carries the key. */
export interface LiveEndpoint {
@@ -52,7 +55,8 @@ export interface LiveEndpoint {
}
export function liveProviderName(provider: LiveProvider): string {
- return provider === "azure" ? "Azure OpenAI" : provider === "fish" ? "Fish Audio" : provider === "gemini" ? "Gemini" : provider === "elevenlabs" ? "ElevenLabs" : "OpenAI";
+ return provider === "azure" ? "Azure OpenAI" : provider === "fish" ? "Fish Audio" : provider === "gemini" ? "Gemini" : provider === "elevenlabs" ? "ElevenLabs"
+ : provider === "custom" ? "The custom endpoint" : "OpenAI";
}
/** Only a loopback http URL is accepted, read at call time. */
@@ -93,6 +97,34 @@ export function azureLiveEndpoint(endpoint: string | undefined, deployment: stri
return root && model ? { provider: "azure", apiBase: `${root}/v1`, model } : null;
}
+/** The versioned API root of a custom OpenAI-compatible endpoint as people paste it (`https://gateway.example.com/v1`, bare, or
+ * with `/live/sessions`): https on any host, or http only on this computer's loopback, since the key is sent there; null for
+ * anything else, or for an address with a user name, password, query or fragment. */
+export function customLiveApiBase(raw: string | undefined): string | null {
+ let url: URL;
+ try {
+ url = new URL(raw?.trim() ?? "");
+ } catch {
+ return null;
+ }
+ if (url.username || url.password || url.search || url.hash) return null;
+ const loopback = url.hostname === "127.0.0.1" || url.hostname === "localhost" || url.hostname === "[::1]";
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) return null;
+ const path = url.pathname.replace(/\/+$/, "").replace(/\/live\/sessions$/i, "");
+ return `${url.origin}${/\/v1$/i.test(path) ? path : `${path}/v1`}`;
+}
+
+export function customLiveModel(raw: string | undefined): string | null {
+ const name = raw?.trim() || LIVE_MODEL;
+ return CUSTOM_MODEL.test(name) ? name : null;
+}
+
+export function customLiveEndpoint(endpoint: string | undefined, model: string | undefined): LiveEndpoint | null {
+ const apiBase = customLiveApiBase(endpoint);
+ const name = customLiveModel(model);
+ return apiBase && name ? { provider: "custom", apiBase, model: name } : null;
+}
+
export function liveSessionsUrl(endpoint: LiveEndpoint = openAiLiveEndpoint()): string {
return `${endpoint.apiBase}/live/sessions`;
}
@@ -224,7 +256,7 @@ export async function createLiveSession(input: CreateLiveSessionInput): Promise<
const endpoint = input.endpoint ?? openAiLiveEndpoint();
const provider = liveProviderName(endpoint.provider);
const key = input.key.trim();
- if (!key) throw new LiveSessionError(`Add an ${provider} API key to use Live calls.`, 409);
+ if (!key) throw new LiveSessionError(endpoint.provider === "custom" ? LIVE_NEEDS_CUSTOM : `Add an ${provider} API key to use Live calls.`, 409);
if (!input.sdp.trim() || Buffer.byteLength(input.sdp) > MAX_SDP_BYTES) {
throw new LiveSessionError("The call could not start: the connection offer was invalid.", 400);
}
@@ -246,8 +278,8 @@ export async function createLiveSession(input: CreateLiveSessionInput): Promise<
response = await (input.fetchImpl ?? fetch)(liveSessionsUrl(endpoint), {
method: "POST",
headers: { ...liveAuthHeaders(endpoint.provider, key), "content-type": "application/json" },
- // fetch drops `authorization` on a redirect to another host, but keeps `api-key`.
- ...(endpoint.provider === "azure" ? { redirect: "error" as const } : {}),
+ // fetch drops `authorization` on a redirect to another host, but keeps `api-key`; a custom endpoint is not followed anywhere else either.
+ ...(endpoint.provider === "azure" || endpoint.provider === "custom" ? { redirect: "error" as const } : {}),
body: JSON.stringify(body),
signal: AbortSignal.timeout(input.timeoutMs ?? CREATE_TIMEOUT_MS),
});
@@ -286,6 +318,11 @@ export function liveErrorMessage(status: number, param?: string, provider: LiveP
if (status === 403) return "This Azure OpenAI resource refused the call. Check its network rules and that the key belongs to it.";
if (status === 404) return "Azure OpenAI has no GPT-Live deployment by that name on this resource. Check the endpoint and the deployment name.";
if (status === 429) return "Azure OpenAI is limiting Live sessions right now (rate limit or quota). Try again in a moment.";
+ } else if (provider === "custom") {
+ if (status === 401) return "The custom endpoint rejected the key. Check the key saved for it.";
+ if (status === 403) return "The custom endpoint refused the call. Check that its key may start Live calls.";
+ if (status === 404) return "The custom endpoint has no Live calls at this address (POST …/v1/live/sessions) or no model by that name. Check the endpoint and the model.";
+ if (status === 429) return "The custom endpoint is limiting Live sessions right now. Try again in a moment.";
} else {
if (status === 401) return "OpenAI rejected the API key. Check the key for Live calls.";
if (status === 403) return "This OpenAI project has no access to GPT-Live. Check the project's model access and billing.";
diff --git a/server/live-config.ts b/server/live-config.ts
index 9d5c64cde4..6687cc68a0 100644
--- a/server/live-config.ts
+++ b/server/live-config.ts
@@ -2,15 +2,18 @@
import { z } from "zod";
export const LIVE_KEY_NEEDS_ENDPOINT = "Save the Azure endpoint first: a Live key works only with the endpoint it was saved for.";
+export const LIVE_KEY_NEEDS_CUSTOM_ENDPOINT = "Save the custom endpoint first: a Live key works only with the endpoint it was saved for.";
const NOWHERE = "nowhere";
-/** Live calls: `key` is a key for Live calls only; with `provider` "openai" (the default) a call without one uses `openai.key`, with "azure" it is the Azure resource's key and is required, with "fish", "gemini" or "elevenlabs" it is not used: Fish Audio calls use the Fish Audio key (`tts.fishKey`), Gemini calls the Gemini key (`tts.geminiKey`) and ElevenLabs calls the ElevenLabs key (`tts.key`). `keyFor` says where `key` may go (`liveKeyTarget`): the server sets it when the key is saved and never takes it from a request; absent, the key is from before Azure was offered, so OpenAI's. `azureEndpoint` is the resource URL and `azureDeployment` the gpt-live-1 deployment name. `fishAgentId` is the Fish Audio agent a "fish" call starts, which the harness sets up on the account of the key whose `fishKeyPrint` is `fishAgentFor`; without `fishAgentFor` (an operator's OMB_FISH_LIVE_AGENT_ID) it is used with any key. `elevenlabsAgentId` and `elevenlabsAgentFor` are the same for an "elevenlabs" call's ElevenLabs agent. `voice` is a GPT-Live voice, `geminiVoice` a Gemini Live voice. */
+/** Live calls: `key` is a key for Live calls only; with `provider` "openai" (the default) a call without one uses `openai.key`, with "azure" it is the Azure resource's key and is required, with "fish", "gemini" or "elevenlabs" it is not used: Fish Audio calls use the Fish Audio key (`tts.fishKey`), Gemini calls the Gemini key (`tts.geminiKey`) and ElevenLabs calls the ElevenLabs key (`tts.key`). `keyFor` says where `key` may go (`liveKeyTarget`): the server sets it when the key is saved and never takes it from a request; absent, the key is from before Azure was offered, so OpenAI's. `azureEndpoint` is the resource URL and `azureDeployment` the gpt-live-1 deployment name; with "custom", `key` is the key of the OpenAI-compatible server at `customEndpoint` and is required, and `customModel` its model. `fishAgentId` is the Fish Audio agent a "fish" call starts, which the harness sets up on the account of the key whose `fishKeyPrint` is `fishAgentFor`; without `fishAgentFor` (an operator's OMB_FISH_LIVE_AGENT_ID) it is used with any key. `elevenlabsAgentId` and `elevenlabsAgentFor` are the same for an "elevenlabs" call's ElevenLabs agent. `voice` is a GPT-Live voice, `geminiVoice` a Gemini Live voice. */
export const liveConfigSchema = z.object({
key: z.string().optional(),
keyFor: z.string().max(300).optional(),
- provider: z.enum(["openai", "azure", "fish", "gemini", "elevenlabs"]).optional(),
+ provider: z.enum(["openai", "azure", "fish", "gemini", "elevenlabs", "custom"]).optional(),
azureEndpoint: z.string().trim().max(300).optional(),
azureDeployment: z.string().trim().max(64).optional(),
+ customEndpoint: z.string().trim().max(300).optional(),
+ customModel: z.string().trim().max(64).optional(),
fishAgentId: z.string().trim().max(128).optional(),
fishAgentFor: z.string().max(64).optional(),
elevenlabsAgentId: z.string().trim().max(128).optional(),
@@ -24,9 +27,11 @@ export const liveConfigSchema = z.object({
export interface LiveConfig {
key?: string;
keyFor?: string;
- provider?: "openai" | "azure" | "fish" | "gemini" | "elevenlabs";
+ provider?: "openai" | "azure" | "fish" | "gemini" | "elevenlabs" | "custom";
azureEndpoint?: string;
azureDeployment?: string;
+ customEndpoint?: string;
+ customModel?: string;
fishAgentId?: string;
fishAgentFor?: string;
elevenlabsAgentId?: string;
@@ -37,13 +42,13 @@ export interface LiveConfig {
idleMinutes?: number;
}
-/** Where a key saved now may go: "openai", or "azure:<host>"; null while Azure is chosen with no endpoint to tie it to.
- * Fish Audio, Gemini and ElevenLabs calls never use this key, so with any of them chosen it stays OpenAI's. */
+/** Where a key saved now may go: "openai", "azure:<host>" or "custom:<host>"; null while Azure or a custom endpoint is chosen
+ * with no endpoint to tie it to. Fish Audio, Gemini and ElevenLabs calls never use this key, so with any of them chosen it stays OpenAI's. */
export function liveKeyTarget(live: LiveConfig | undefined): string | null {
- if (live?.provider !== "azure") return "openai";
+ if (live?.provider !== "azure" && live?.provider !== "custom") return "openai";
try {
- const host = new URL(live.azureEndpoint?.trim() ?? "").host.toLowerCase();
- return host ? `azure:${host}` : null;
+ const host = new URL((live.provider === "azure" ? live.azureEndpoint : live.customEndpoint)?.trim() ?? "").host.toLowerCase();
+ return host ? `${live.provider}:${host}` : null;
} catch {
return null;
}
@@ -63,7 +68,7 @@ export function liveSavePatch(current: LiveConfig | undefined, patch: LiveConfig
const { keyFor: _fromRequest, ...asked } = patch;
const target = liveKeyTarget({ ...current, ...asked });
if (asked.key?.trim()) {
- if (!target) throw Object.assign(new Error(LIVE_KEY_NEEDS_ENDPOINT), { status: 400 });
+ if (!target) throw Object.assign(new Error({ ...current, ...asked }.provider === "custom" ? LIVE_KEY_NEEDS_CUSTOM_ENDPOINT : LIVE_KEY_NEEDS_ENDPOINT), { status: 400 });
return { ...asked, keyFor: target };
}
return asked.key !== undefined || target !== liveKeyTarget(current) ? { ...asked, key: "", keyFor: NOWHERE } : asked;
@@ -78,16 +83,19 @@ export function liveConfigWithEnv(live: LiveConfig | undefined, env: NodeJS.Proc
next.key = envKey;
}
const provider = env.OMB_LIVE_PROVIDER?.trim().toLowerCase();
- if (provider === "openai" || provider === "azure" || provider === "fish" || provider === "gemini" || provider === "elevenlabs") next.provider = provider;
+ if (provider === "openai" || provider === "azure" || provider === "fish" || provider === "gemini" || provider === "elevenlabs" || provider === "custom") next.provider = provider;
if (env.OMB_AZURE_OPENAI_LIVE_ENDPOINT !== undefined) next.azureEndpoint = env.OMB_AZURE_OPENAI_LIVE_ENDPOINT.trim();
if (env.OMB_AZURE_OPENAI_LIVE_DEPLOYMENT !== undefined) next.azureDeployment = env.OMB_AZURE_OPENAI_LIVE_DEPLOYMENT.trim();
+ if (env.OMB_CUSTOM_LIVE_ENDPOINT !== undefined) next.customEndpoint = env.OMB_CUSTOM_LIVE_ENDPOINT.trim();
+ if (env.OMB_CUSTOM_LIVE_MODEL !== undefined) next.customModel = env.OMB_CUSTOM_LIVE_MODEL.trim();
if (env.OMB_FISH_LIVE_AGENT_ID?.trim()) {
next.fishAgentId = env.OMB_FISH_LIVE_AGENT_ID.trim();
delete next.fishAgentFor;
}
- // Set together in the environment, the key and the Azure endpoint are the operator's own pairing. A `keyFor` from the
+ // Set together in the environment, the key and the Azure (or custom) endpoint are the operator's own pairing. A `keyFor` from the
// file stands: saves mirror settings into the environment, so they must not be able to pair a forgotten key.
- if (envKey?.trim() && provider === "azure" && env.OMB_AZURE_OPENAI_LIVE_ENDPOINT?.trim() && next.keyFor === undefined) next.keyFor = liveKeyTarget(next) ?? NOWHERE;
+ const envEndpoint = provider === "azure" ? env.OMB_AZURE_OPENAI_LIVE_ENDPOINT : provider === "custom" ? env.OMB_CUSTOM_LIVE_ENDPOINT : undefined;
+ if (envKey?.trim() && envEndpoint?.trim() && next.keyFor === undefined) next.keyFor = liveKeyTarget(next) ?? NOWHERE;
return next;
}
@@ -97,6 +105,8 @@ export function liveSettingEnv(live: LiveConfig | undefined): Array<[value: stri
[live?.provider, "OMB_LIVE_PROVIDER"],
[live?.azureEndpoint, "OMB_AZURE_OPENAI_LIVE_ENDPOINT"],
[live?.azureDeployment, "OMB_AZURE_OPENAI_LIVE_DEPLOYMENT"],
+ [live?.customEndpoint, "OMB_CUSTOM_LIVE_ENDPOINT"],
+ [live?.customModel, "OMB_CUSTOM_LIVE_MODEL"],
];
}
diff --git a/server/live-custom.test.ts b/server/live-custom.test.ts
new file mode 100644
index 0000000000..4f6e9931c7
--- /dev/null
+++ b/server/live-custom.test.ts
@@ -0,0 +1,171 @@
+// Live calls through a custom OpenAI-compatible endpoint: the address rules, the key it is tied to, and who may call.
+import { createServer, type IncomingMessage, type RequestListener, type Server } from "node:http";
+import type { AddressInfo } from "node:net";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+import type { AppConfig } from "./config.ts";
+import { LIVE_CUSTOM_REFUSAL, liveScopeRefusal } from "./live-access.ts";
+import {
+ createLiveSession,
+ customLiveApiBase,
+ customLiveEndpoint,
+ LIVE_DATA_CHANNEL,
+ LIVE_MODEL,
+ LIVE_NEEDS_CUSTOM,
+ liveAttachUrl,
+ liveAuthHeaders,
+ liveErrorMessage,
+ liveSessionsUrl,
+} from "./live-call.ts";
+import { LIVE_KEY_NEEDS_CUSTOM_ENDPOINT, liveConfigWithEnv, liveKeyTarget, liveSavePatch, liveSettingEnv, usableLiveKey } from "./live-config.ts";
+import { liveCallEndpoint, liveCallKey, liveCallSettings, liveSettingsFor, liveSettingsForClient } from "./live-settings.ts";
+
+const OFFER = "v=0\r\no=- 1 2 IN IP4 127.0.0.1\r\n";
+const BOT = { name: "Ada", title: "Tech Lead", description: "Leads the engineering team." };
+const GATEWAY = "https://gateway.example.com/v1";
+const custom = { provider: "custom" as const, customEndpoint: GATEWAY, customModel: "gpt-live-1" };
+const keyFor = "custom:gateway.example.com";
+
+function okFetch() {
+ const answer = { session: { id: "live_9" }, transport: { type: "webrtc", sdp: "v=0 answer" } };
+ return vi.fn(async (_url: string | URL | Request, _init?: RequestInit) => new Response(JSON.stringify(answer), { status: 201 }));
+}
+
+describe("customLiveApiBase", () => {
+ it("accepts the address however it is pasted, and keeps a gateway's own path", () => {
+ for (const url of [
+ "https://gateway.example.com",
+ " https://gateway.example.com/ ",
+ "https://gateway.example.com/v1",
+ "https://gateway.example.com/v1/",
+ "https://gateway.example.com/v1/live/sessions",
+ ]) expect(customLiveApiBase(url), url).toBe("https://gateway.example.com/v1");
+ expect(customLiveApiBase("https://gw.example.com/team-a/openai/v1")).toBe("https://gw.example.com/team-a/openai/v1");
+ expect(customLiveApiBase("https://gw.example.com:8443/proxy")).toBe("https://gw.example.com:8443/proxy/v1");
+ });
+ it("allows plain http only on this computer's loopback", () => {
+ expect(customLiveApiBase("http://127.0.0.1:4555")).toBe("http://127.0.0.1:4555/v1");
+ expect(customLiveApiBase("http://localhost:4555/v1")).toBe("http://localhost:4555/v1");
+ expect(customLiveApiBase("http://[::1]:4555/v1")).toBe("http://[::1]:4555/v1");
+ });
+ it("refuses anything the key must not be sent to", () => {
+ for (const url of [
+ undefined,
+ "",
+ "gateway.example.com",
+ "http://gateway.example.com/v1",
+ "http://10.0.0.5:8080/v1",
+ "ws://127.0.0.1:4555/v1",
+ "ftp://gateway.example.com",
+ "https://user:[email protected]/v1",
+ "https://gateway.example.com/v1?key=x",
+ "https://gateway.example.com/v1#x",
+ ]) expect(customLiveApiBase(url), String(url)).toBeNull();
+ });
+ it("points calls at the endpoint with the model, gpt-live-1 when none is saved", () => {
+ const endpoint = customLiveEndpoint(GATEWAY, "my-live")!;
+ expect(endpoint).toEqual({ provider: "custom", apiBase: GATEWAY, model: "my-live" });
+ expect(liveSessionsUrl(endpoint)).toBe("https://gateway.example.com/v1/live/sessions");
+ expect(liveAttachUrl("s/1", endpoint)).toBe("wss://gateway.example.com/v1/live/sessions/s%2F1/attach");
+ expect(customLiveEndpoint(GATEWAY, "")?.model).toBe(LIVE_MODEL);
+ expect(customLiveEndpoint(GATEWAY, "openai/gpt-live-1")?.model).toBe("openai/gpt-live-1");
+ expect(customLiveEndpoint(GATEWAY, "bad name")).toBeNull();
+ expect(customLiveEndpoint("http://gateway.example.com", "m")).toBeNull();
+ });
+});
+
+describe("createLiveSession on a custom endpoint", () => {
+ it("sends the key as a bearer token, the model, and the client's tool list like OpenAI", async () => {
+ const fetchImpl = okFetch();
+ const endpoint = customLiveEndpoint(GATEWAY, "my-live")!;
+ const result = await createLiveSession({ key: " gw-secret ", endpoint, sdp: OFFER, bot: BOT, history: [], cloudHome: false, fetchImpl });
+ expect(result).toEqual({ sessionId: "live_9", sdp: "v=0 answer" });
+ const [url, init] = fetchImpl.mock.calls[0];
+ expect(url).toBe("https://gateway.example.com/v1/live/sessions");
+ expect((init!.headers as Record<string, string>).authorization).toBe("Bearer gw-secret");
+ expect(init?.redirect).toBe("error");
+ const body = JSON.parse(String(init?.body));
+ expect(body.session.model).toBe("my-live");
+ expect(body.session.client).toEqual({ data_channel: LIVE_DATA_CHANNEL });
+ expect(String(init?.body)).not.toContain("gw-secret");
+ expect(liveAuthHeaders("custom", "k")).toEqual({ authorization: "Bearer k" });
+ });
+ it("names the custom endpoint in its errors", async () => {
+ const endpoint = customLiveEndpoint(GATEWAY, undefined)!;
+ const refuse = vi.fn(async () => new Response("{}", { status: 404 }));
+ await expect(createLiveSession({ key: "k", endpoint, sdp: OFFER, bot: BOT, history: [], cloudHome: false, fetchImpl: refuse }))
+ .rejects.toMatchObject({ status: 502, message: expect.stringContaining("custom endpoint") });
+ expect(liveErrorMessage(401, undefined, "custom")).toMatch(/^The custom endpoint rejected the key/);
+ await expect(createLiveSession({ key: "", endpoint, sdp: OFFER, bot: BOT, history: [], cloudHome: false, fetchImpl: refuse }))
+ .rejects.toMatchObject({ status: 409, message: LIVE_NEEDS_CUSTOM });
+ });
+
+ const servers: Server[] = [];
+ afterEach(() => {
+ for (const server of servers.splice(0)) {
+ server.closeAllConnections();
+ server.close();
+ }
+ });
+ it("refuses a redirect, so the key never reaches another host", async () => {
+ const reached: IncomingMessage[] = [];
+ const listen = async (handler: RequestListener) => {
+ const server = createServer(handler);
+ servers.push(server);
+ await new Promise<void>((ready) => server.listen(0, "127.0.0.1", ready));
+ return (server.address() as AddressInfo).port;
+ };
+ const other = await listen((req, res) => { reached.push(req); res.end("{}"); });
+ const first = await listen((_req, res) => { res.writeHead(307, { location: `http://127.0.0.1:${other}/elsewhere` }).end(); });
+ const endpoint = customLiveEndpoint(`http://127.0.0.1:${first}/v1`, "m")!;
+ await expect(createLiveSession({ key: "made-up-key", endpoint, sdp: OFFER, bot: BOT, history: [], cloudHome: false })).rejects.toMatchObject({ status: 502 });
+ expect(reached).toEqual([]);
+ });
+});
+
+describe("the key a custom endpoint's calls use", () => {
+ it("is only the key saved for that endpoint, never the OpenAI API key", () => {
+ const cfg = { live: custom, openai: { key: "sk-openai" } } as AppConfig;
+ expect(liveCallKey(cfg)).toBeNull();
+ expect(liveCallSettings(cfg)).toMatchObject({ provider: "custom", key: "", setupProblem: LIVE_NEEDS_CUSTOM });
+ const saved = { live: { ...custom, key: "gw-secret", keyFor }, openai: { key: "sk-openai" } } as AppConfig;
+ expect(liveCallKey(saved)).toEqual({ key: "gw-secret", source: "live" });
+ expect(liveCallEndpoint(saved)).toEqual({ provider: "custom", apiBase: GATEWAY, model: "gpt-live-1" });
+ expect(liveCallSettings(saved)).toMatchObject({ provider: "custom", key: "gw-secret", setupProblem: null });
+ expect(liveSettingsFor(saved)).toMatchObject({ configured: true, keySource: "live", provider: "custom", customEndpoint: GATEWAY, customModel: "gpt-live-1" });
+ expect(JSON.stringify(liveSettingsFor(saved))).not.toContain("gw-secret");
+ });
+ it("is not a key saved for another host, for Azure on the same host, or for OpenAI", () => {
+ expect(liveKeyTarget(custom)).toBe(keyFor);
+ expect(liveKeyTarget({ provider: "custom", customEndpoint: "nope" })).toBeNull();
+ for (const keyForOther of ["openai", "custom:other.example.com", "azure:gateway.example.com", undefined]) {
+ expect(usableLiveKey({ ...custom, key: "k", keyFor: keyForOther }), String(keyForOther)).toBeUndefined();
+ }
+ expect(usableLiveKey({ ...custom, key: "k", keyFor })).toBe("k");
+ });
+ it("ties a new key to the endpoint and forgets it when the endpoint moves", () => {
+ expect(liveSavePatch(custom, { key: "k" })).toEqual({ key: "k", keyFor });
+ expect(() => liveSavePatch({ provider: "custom" }, { key: "k" })).toThrow(LIVE_KEY_NEEDS_CUSTOM_ENDPOINT);
+ expect(liveSavePatch({ ...custom, key: "k", keyFor }, { customEndpoint: "https://elsewhere.example.com/v1" })).toMatchObject({ key: "", keyFor: "nowhere" });
+ expect(liveSavePatch({ ...custom, key: "k", keyFor }, { customModel: "other" })).toEqual({ customModel: "other" });
+ });
+ it("hides the endpoint and model from a caller without the admin scope", () => {
+ const client = liveSettingsForClient(liveSettingsFor({ live: { ...custom, key: "k", keyFor } } as AppConfig));
+ expect(client).toEqual({ configured: true, keySource: "live", provider: "custom", voice: "", readTypedReplies: true, idleMinutes: 5 });
+ });
+});
+
+describe("a custom endpoint from the environment", () => {
+ it("reads the endpoint and model, and pairs a key set beside them", () => {
+ const env = { OMB_LIVE_PROVIDER: "custom", OMB_CUSTOM_LIVE_ENDPOINT: ` ${GATEWAY} `, OMB_CUSTOM_LIVE_MODEL: "m", OMB_OPENAI_LIVE_KEY: "gw" };
+ expect(liveConfigWithEnv(undefined, env)).toEqual({ provider: "custom", customEndpoint: GATEWAY, customModel: "m", key: "gw", keyFor });
+ expect(liveConfigWithEnv({ keyFor: "nowhere" }, env).keyFor).toBe("nowhere");
+ expect(liveSettingEnv(custom)).toEqual(expect.arrayContaining([[GATEWAY, "OMB_CUSTOM_LIVE_ENDPOINT"], ["gpt-live-1", "OMB_CUSTOM_LIVE_MODEL"]]));
+ });
+});
+
+describe("who may call through a custom endpoint", () => {
+ it("names the custom endpoint to a caller without the admin scope", () => {
+ expect(liveScopeRefusal({ live: custom }, "POST", "/api/live/session")).toBe(LIVE_CUSTOM_REFUSAL);
+ });
+});
diff --git a/server/live-settings.ts b/server/live-settings.ts
index 756d6d1d86..6224d4d612 100644
--- a/server/live-settings.ts
+++ b/server/live-settings.ts
@@ -1,6 +1,6 @@
import type { LiveKeySource, LiveSettings } from "../shared/wire.ts";
import { saveConfig, syncCredentialEnv, type AppConfig } from "./config.ts";
-import { azureLiveEndpoint, LIVE_NEEDS_AZURE, LIVE_NEEDS_ELEVENLABS, LIVE_NEEDS_FISH, LIVE_NEEDS_GEMINI, LIVE_NEEDS_KEY, openAiLiveEndpoint, type LiveEndpoint } from "./live-call.ts";
+import { azureLiveEndpoint, customLiveEndpoint, LIVE_NEEDS_AZURE, LIVE_NEEDS_CUSTOM, LIVE_NEEDS_ELEVENLABS, LIVE_NEEDS_FISH, LIVE_NEEDS_GEMINI, LIVE_NEEDS_KEY, openAiLiveEndpoint, type LiveEndpoint } from "./live-call.ts";
import { liveSavePatch, usableLiveKey, type LiveConfig as LiveConfigSection } from "./live-config.ts";
import { fishLiveEndpoint, usableFishAgent } from "./live-fish.ts";
import { voiceCredential } from "./included-services.ts";
@@ -13,7 +13,7 @@ type LiveConfig = Pick<AppConfig, "live" | "openai" | "tts">;
/** A saved Live key goes only to the provider and host it was saved for (`usableLiveKey`), the OpenAI API key only ever to
* OpenAI, the Fish Audio key only to Fish Audio, the Gemini key only to Gemini and the person's own ElevenLabs key only to
- * ElevenLabs. */
+ * ElevenLabs. A custom endpoint gets only the key saved for it. */
export function liveCallKey(cfg: LiveConfig, env: NodeJS.ProcessEnv = process.env): { key: string; source: LiveKeySource } | null {
if (cfg.live?.provider === "fish") {
const fish = cfg.tts?.fishKey?.trim();
@@ -30,15 +30,16 @@ export function liveCallKey(cfg: LiveConfig, env: NodeJS.ProcessEnv = process.en
}
const live = usableLiveKey(cfg.live);
if (live) return { key: live, source: "live" };
- if (cfg.live?.provider === "azure") return null;
+ if (cfg.live?.provider === "azure" || cfg.live?.provider === "custom") return null;
const openai = cfg.openai?.key?.trim();
return openai ? { key: openai, source: "openai" } : null;
}
-/** null when Azure is chosen but its endpoint or deployment is missing or not valid. On Fish Audio, `model` is "" until the
+/** null when Azure (or a custom endpoint) is chosen but its endpoint or deployment (model) is missing or not valid. On Fish Audio, `model` is "" until the
* harness has set up an agent on the account of the Fish Audio key. */
export function liveCallEndpoint(cfg: LiveConfig, env: NodeJS.ProcessEnv = process.env): LiveEndpoint | null {
if (cfg.live?.provider === "azure") return azureLiveEndpoint(cfg.live.azureEndpoint, cfg.live.azureDeployment);
+ if (cfg.live?.provider === "custom") return customLiveEndpoint(cfg.live.customEndpoint, cfg.live.customModel);
if (cfg.live?.provider === "fish") return fishLiveEndpoint(usableFishAgent(cfg.live, cfg.tts?.fishKey ?? ""), env);
if (cfg.live?.provider === "gemini") return geminiLiveEndpoint(env);
if (cfg.live?.provider === "elevenlabs") return elevenLabsLiveEndpoint(usableElevenLabsAgent(cfg.live, cfg.tts?.key ?? ""), env);
@@ -48,7 +49,7 @@ export function liveCallEndpoint(cfg: LiveConfig, env: NodeJS.ProcessEnv = proce
export function liveSetupProblem(cfg: LiveConfig): string | null {
const provider = cfg.live?.provider;
const missing = provider === "azure" ? LIVE_NEEDS_AZURE : provider === "fish" ? LIVE_NEEDS_FISH : provider === "gemini" ? LIVE_NEEDS_GEMINI
- : provider === "elevenlabs" ? LIVE_NEEDS_ELEVENLABS : LIVE_NEEDS_KEY;
+ : provider === "elevenlabs" ? LIVE_NEEDS_ELEVENLABS : provider === "custom" ? LIVE_NEEDS_CUSTOM : LIVE_NEEDS_KEY;
if (!liveCallKey(cfg)) return missing;
return liveCallEndpoint(cfg) ? null : missing;
}
@@ -65,8 +66,8 @@ export function liveCallSettings(cfg: AppConfig) {
return { key: liveCallKey(cfg)?.key ?? "", endpoint: liveCallEndpoint(cfg), setupProblem: liveSetupProblem(cfg), ...liveSettingsFor(cfg) };
}
-/** A caller without the admin scope learns which service calls use, not which Azure resource. */
-export function liveSettingsForClient({ azureEndpoint: _endpoint, azureDeployment: _deployment, ...settings }: LiveSettings): LiveSettings {
+/** A caller without the admin scope learns which service calls use, not which Azure resource or custom endpoint. */
+export function liveSettingsForClient({ azureEndpoint: _endpoint, azureDeployment: _deployment, customEndpoint: _custom, customModel: _model, ...settings }: LiveSettings): LiveSettings {
return settings;
}
@@ -77,9 +78,11 @@ export function liveSettingsFor(cfg: AppConfig): LiveSettings {
return {
configured: liveSetupProblem(cfg) === null,
...(key ? { keySource: key.source } : {}),
- ...(provider === "azure" || provider === "fish" || provider === "gemini" || provider === "elevenlabs" ? { provider } : {}),
+ ...(provider === "azure" || provider === "fish" || provider === "gemini" || provider === "elevenlabs" || provider === "custom" ? { provider } : {}),
...(cfg.live?.azureEndpoint ? { azureEndpoint: cfg.live.azureEndpoint } : {}),
...(cfg.live?.azureDeployment ? { azureDeployment: cfg.live.azureDeployment } : {}),
+ ...(cfg.live?.customEndpoint ? { customEndpoint: cfg.live.customEndpoint } : {}),
+ ...(cfg.live?.customModel ? { customModel: cfg.live.customModel } : {}),
voice: cfg.live?.voice ?? "",
...(cfg.live?.geminiVoice ? { geminiVoice: cfg.live.geminiVoice } : {}),
readTypedReplies: cfg.live?.readTypedReplies ?? true,
diff --git a/server/routes/live.test.ts b/server/routes/live.test.ts
index 243b9da62d..042a10d291 100644
--- a/server/routes/live.test.ts
+++ b/server/routes/live.test.ts
@@ -155,6 +155,17 @@ describe("live routes", () => {
expect((await request(d, "PATCH", "/api/live/settings", { azureEndpoint: "", azureDeployment: "" })).status).toBe(200);
expect(d.saved).toEqual([azure, { azureEndpoint: "", azureDeployment: "" }]);
});
+ it("saves a custom endpoint and model, refusing an address the key must not reach", async () => {
+ const d = deps();
+ const custom = { provider: "custom", customEndpoint: "https://gateway.example.com/v1", customModel: "gpt-live-1" };
+ expect(await request(d, "PATCH", "/api/live/settings", custom)).toMatchObject({ status: 200, body: { live: custom } });
+ for (const customEndpoint of ["http://gateway.example.com/v1", "https://u:[email protected]", "gateway.example.com"]) {
+ expect(await request(d, "PATCH", "/api/live/settings", { customEndpoint }), customEndpoint).toMatchObject({ status: 400, body: { error: expect.stringContaining("https address") } });
+ }
+ expect(await request(d, "PATCH", "/api/live/settings", { customModel: "a b" })).toMatchObject({ status: 400, body: { error: expect.stringContaining("model") } });
+ expect((await request(d, "PATCH", "/api/live/settings", { customEndpoint: "http://127.0.0.1:4555/v1", customModel: "" })).status).toBe(200);
+ expect(d.saved).toEqual([custom, { customEndpoint: "http://127.0.0.1:4555/v1", customModel: "" }]);
+ });
it("saves Fish Audio as the provider, and takes no agent from a request", async () => {
const d = deps();
expect(await request(d, "PATCH", "/api/live/settings", { provider: "fish" })).toMatchObject({ status: 200, body: { live: { provider: "fish" } } });
diff --git a/server/routes/live.ts b/server/routes/live.ts
index baea08fcd6..5a00df5aac 100644
--- a/server/routes/live.ts
+++ b/server/routes/live.ts
@@ -3,7 +3,7 @@ import type { IncomingMessage } from "node:http";
import { z } from "zod";
import type { LiveFishRelayCommand, LiveFishRelayEvent, LiveProvider, LiveSettings } from "../../shared/wire.ts";
import { GEMINI_LIVE_VOICE_OPTIONS } from "../../shared/live-call.ts";
-import { azureLiveDeployment, azureOpenAiRoot, LiveSessionError, MAX_SDP_BYTES } from "../live-call.ts";
+import { azureLiveDeployment, azureOpenAiRoot, customLiveApiBase, customLiveModel, LiveSessionError, MAX_SDP_BYTES } from "../live-call.ts";
import { LiveCallBusyError, type LiveCallController } from "../live-call-controller.ts";
import { RELAY_POLL_MS } from "../live-fish.ts";
import { PASS, type RouteContext, type RouteHandler } from "./table.ts";
@@ -14,7 +14,7 @@ export interface LiveRouteDeps {
deviceRevoked?: (device: string) => void;
resolveTarget(botId: string, threadId: string | undefined): { botId: string; botName: string; threadId: string } | null;
settings(): LiveSettings;
- saveSettings(patch: { provider?: LiveProvider; azureEndpoint?: string; azureDeployment?: string; voice?: string; geminiVoice?: string; readTypedReplies?: boolean; idleMinutes?: number }): Promise<LiveSettings>;
+ saveSettings(patch: { provider?: LiveProvider; azureEndpoint?: string; azureDeployment?: string; customEndpoint?: string; customModel?: string; voice?: string; geminiVoice?: string; readTypedReplies?: boolean; idleMinutes?: number }): Promise<LiveSettings>;
/** A running relayed (Fish Audio, Gemini or ElevenLabs) call's relay, only for the token its start answered with. */
fishRelay(sessionId: string, token: string): { receive(events: LiveFishRelayEvent[], from?: number): void; poll(waitMs: number): Promise<{ commands: LiveFishRelayCommand[]; closed: boolean }> } | null;
}
@@ -46,10 +46,13 @@ const relayBody = z.object({
}).strict();
// Strict, so `key` is refused rather than ignored: the key is saved only through the credential store or PUT /api/config.
const settingsBody = z.object({
- provider: z.enum(["openai", "azure", "fish", "gemini", "elevenlabs"]).optional(),
+ provider: z.enum(["openai", "azure", "fish", "gemini", "elevenlabs", "custom"]).optional(),
// "" clears the field. Anything else must be an https Azure OpenAI host, since the key is sent there.
azureEndpoint: z.string().trim().max(300).refine((url) => url === "" || azureOpenAiRoot(url) !== null).optional(),
azureDeployment: z.string().trim().max(64).refine((name) => name === "" || azureLiveDeployment(name) === name).optional(),
+ // The same for a custom endpoint: https, or http only on this computer's loopback.
+ customEndpoint: z.string().trim().max(300).refine((url) => url === "" || customLiveApiBase(url) !== null).optional(),
+ customModel: z.string().trim().max(64).refine((name) => name === "" || customLiveModel(name) === name).optional(),
voice: z.string().trim().max(40).regex(/^[a-z]*$/).optional(),
// "" goes back to the default voice.
geminiVoice: z.string().trim().refine((name) => name === "" || GEMINI_LIVE_VOICE_OPTIONS.some((option) => option.id === name)).optional(),
@@ -128,6 +131,8 @@ export function createLiveRoutes(deps: LiveRouteDeps): RouteHandler {
const field = parsed.error.issues[0]?.path[0];
if (field === "azureEndpoint") return json(res, 400, { error: "The Azure endpoint must be the https address of an Azure OpenAI resource, like https://my-resource.openai.azure.com." });
if (field === "azureDeployment") return json(res, 400, { error: "The Azure deployment name may use letters, digits, '-', '_' and '.', up to 64 characters." });
+ if (field === "customEndpoint") return json(res, 400, { error: "The custom endpoint must be an https address, like https://gateway.example.com/v1, or http only on this computer (127.0.0.1 or localhost)." });
+ if (field === "customModel") return json(res, 400, { error: "The model may use letters, digits, '-', '_', '.', ':' and '/', up to 64 characters." });
return json(res, 400, { error: "Those Live settings are not valid." });
}
if (!Object.keys(parsed.data).length) return json(res, 400, { error: "nothing to save" });
diff --git a/src/components/LiveCallSettings.tsx b/src/components/LiveCallSettings.tsx
index ce764ad969..13a0be15aa 100644
--- a/src/components/LiveCallSettings.tsx
+++ b/src/components/LiveCallSettings.tsx
@@ -26,6 +26,7 @@ export function LiveCallSettings({ onClose }: { onClose: () => void }) {
dialog?.querySelector<HTMLElement>("select, input, button")?.focus();
}, []);
const azure = live.provider === "azure";
+ const custom = live.provider === "custom";
const fish = live.provider === "fish";
const gemini = live.provider === "gemini";
const elevenlabs = live.provider === "elevenlabs";
@@ -131,13 +132,13 @@ export function LiveCallSettings({ onClose }: { onClose: () => void }) {
)}
</span>
</div>
- {!hasKey && (azure || fish || gemini || elevenlabs) && <div className="-mt-2 text-[12px] text-ink-tertiary">{t(copy.missing)}</div>}
- {live.keySource !== "live" && !azure && !fish && !gemini && !elevenlabs && (
+ {!hasKey && (azure || custom || fish || gemini || elevenlabs) && <div className="-mt-2 text-[12px] text-ink-tertiary">{t(copy.missing)}</div>}
+ {live.keySource !== "live" && !azure && !custom && !fish && !gemini && !elevenlabs && (
<div className="-mt-2 text-[12px] text-ink-tertiary">{t(live.keySource === "openai" ? "call.live.keyFromApiKeys" : "call.live.needsKey")} <KeysLink id="openai" purpose="liveCalls" /></div>
)}
{/* Keyed by provider: a key typed for one provider is never saved for another. */}
{changingKey && <LiveKeySetup key={state.config?.live?.provider ?? "openai"} compact locked={providerSaving} onSaving={setKeySaving} onSaved={() => setChangingKey(false)} />}
- <div className="text-[12px] text-ink-tertiary">{liveDisclosure({ cloudHome: state.config?.cloudHome === true, azure, fish, gemini, elevenlabs })} {t(copy.cost)}</div>
+ <div className="text-[12px] text-ink-tertiary">{liveDisclosure({ cloudHome: state.config?.cloudHome === true, azure, custom, fish, gemini, elevenlabs })} {t(copy.cost)}</div>
{error && <div className="text-[12px] text-danger">{error}</div>}
</div>
);
diff --git a/src/components/LiveKeyNeeded.tsx b/src/components/LiveKeyNeeded.tsx
index c05576788d..bbf59b6c3c 100644
--- a/src/components/LiveKeyNeeded.tsx
+++ b/src/components/LiveKeyNeeded.tsx
@@ -14,12 +14,13 @@ export function LiveKeyNeeded() {
const titleId = useId();
const live = state.config?.live;
const azure = live?.provider === "azure";
+ const custom = live?.provider === "custom";
const fish = live?.provider === "fish";
const gemini = live?.provider === "gemini";
const elevenlabs = live?.provider === "elevenlabs";
const copy = liveKeyCopy(live?.provider);
// A key is tied to the endpoint it is saved for, so the endpoint comes first.
- const keyForm = (azure && Boolean(live?.azureEndpoint) && live?.keySource !== "live") || (fish && live?.keySource !== "fishAudio") || (gemini && live?.keySource !== "gemini")
+ const keyForm = (Boolean((azure && live?.azureEndpoint) || (custom && live?.customEndpoint)) && live?.keySource !== "live") || (fish && live?.keySource !== "fishAudio") || (gemini && live?.keySource !== "gemini")
|| (elevenlabs && live?.keySource !== "elevenlabs");
return <section aria-labelledby={titleId} className="flex flex-col gap-2.5 rounded-xl border border-hairline bg-panel p-4 text-left text-[13px]">
<div className="flex items-start gap-2.5">
@@ -27,9 +28,9 @@ export function LiveKeyNeeded() {
<h2 id={titleId} className="text-[14px] font-medium leading-[1.4] text-ink">{t(copy.needs)}</h2>
</div>
<ProviderAndKey provider={live?.provider ?? "openai"} keyForm={keyForm} />
- {(azure || fish || gemini || elevenlabs) && <DismissWhenReady ready={live?.configured === true} />}
- {!azure && !fish && !gemini && !elevenlabs && <button type="button" className="ui-button ui-button-primary self-start" onClick={() => { dismissLiveNotice(); dispatch(openKeySettings("openai", "liveCalls")); }}>{t("call.live.openApiKeys")}</button>}
- <p className="text-[12px] leading-[1.45] text-ink-tertiary">{!keyForm && `${liveDisclosure({ cloudHome: state.config?.cloudHome === true, azure, fish, gemini, elevenlabs })} `}{t(copy.cost)}</p>
+ {(azure || custom || fish || gemini || elevenlabs) && <DismissWhenReady ready={live?.configured === true} />}
+ {!azure && !custom && !fish && !gemini && !elevenlabs && <button type="button" className="ui-button ui-button-primary self-start" onClick={() => { dismissLiveNotice(); dispatch(openKeySettings("openai", "liveCalls")); }}>{t("call.live.openApiKeys")}</button>}
+ <p className="text-[12px] leading-[1.45] text-ink-tertiary">{!keyForm && `${liveDisclosure({ cloudHome: state.config?.cloudHome === true, azure, custom, fish, gemini, elevenlabs })} `}{t(copy.cost)}</p>
</section>;
}
diff --git a/src/components/LiveKeySetup.tsx b/src/components/LiveKeySetup.tsx
index 419353624b..a2c314fbb1 100644
--- a/src/components/LiveKeySetup.tsx
+++ b/src/components/LiveKeySetup.tsx
@@ -18,6 +18,7 @@ export function LiveKeySetup({ onSaved, onSaving, locked = false, compact = fals
const { state, dispatch } = useStore();
const provider = state.config?.live?.provider;
const azure = provider === "azure";
+ const custom = provider === "custom";
const fish = provider === "fish";
const gemini = provider === "gemini";
const elevenlabs = provider === "elevenlabs";
@@ -65,14 +66,14 @@ export function LiveKeySetup({ onSaved, onSaving, locked = false, compact = fals
>
<div className="text-[14px] font-medium text-ink">{t(copy.title)}</div>
<div className="text-[13px] leading-[1.45] text-ink-secondary">{t(copy.explain)}</div>
- <div className="text-[13px] leading-[1.45] text-ink-secondary">{liveDisclosure({ cloudHome: state.config?.cloudHome === true, azure, fish, gemini, elevenlabs })}</div>
+ <div className="text-[13px] leading-[1.45] text-ink-secondary">{liveDisclosure({ cloudHome: state.config?.cloudHome === true, azure, custom, fish, gemini, elevenlabs })}</div>
<input
type="password"
autoComplete="off"
spellCheck={false}
value={key}
onChange={(event) => setKey(event.target.value)}
- placeholder={azure || fish || gemini ? "…" : elevenlabs ? "sk_…" : "sk-…"}
+ placeholder={azure || custom || fish || gemini ? "…" : elevenlabs ? "sk_…" : "sk-…"}
aria-label={t(copy.field)}
className="rounded-lg border border-hairline bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent/60"
/>
diff --git a/src/components/LiveProviderSettings.tsx b/src/components/LiveProviderSettings.tsx
index 9275c3b3d4..af8c64957d 100644
--- a/src/components/LiveProviderSettings.tsx
+++ b/src/components/LiveProviderSettings.tsx
@@ -6,20 +6,17 @@ import type { LiveProvider, LiveSettings } from "../../shared/wire";
import { Select } from "./Select";
import { KEY_FIELD } from "./keys/KeyRow";
-type ProviderPatch = Partial<Pick<LiveSettings, "provider" | "azureEndpoint" | "azureDeployment">>;
+type ProviderPatch = Partial<Pick<LiveSettings, "provider" | "azureEndpoint" | "azureDeployment" | "customEndpoint" | "customModel">>;
const FIELD = KEY_FIELD;
-/** `locked` holds the provider and Azure endpoint while a key save is pending; `onSaving` reports a pending change to them. */
+/** `locked` holds the provider and endpoint while a key save is pending; `onSaving` reports a pending change to them. */
export function LiveProviderSettings({ locked = false, onSaving }: { locked?: boolean; onSaving?: (saving: boolean) => void } = {}) {
const { state, dispatch } = useStore();
const live: LiveSettings = state.config?.live ?? { configured: false, voice: "", readTypedReplies: true, idleMinutes: 5 };
const provider: LiveProvider = live.provider ?? "openai";
- const [endpoint, setEndpoint] = useState(live.azureEndpoint ?? "");
- const [deployment, setDeployment] = useState(live.azureDeployment ?? "");
const [saving, setSaving] = useState(false);
const [error, setError] = useState<string | null>(null);
- const azureChanged = endpoint.trim() !== (live.azureEndpoint ?? "") || deployment.trim() !== (live.azureDeployment ?? "");
const save = async (patch: ProviderPatch) => {
if (locked) return;
@@ -52,52 +49,11 @@ export function LiveProviderSettings({ locked = false, onSaving }: { locked?: bo
<option value="fish">{t("call.live.provider.fish")}</option>
<option value="gemini">{t("call.live.provider.gemini")}</option>
<option value="elevenlabs">{t("call.live.provider.elevenlabs")}</option>
+ <option value="custom">{t("call.live.provider.custom")}</option>
</Select>
</label>
- {provider === "azure" && (
- <form
- className="flex flex-col gap-2"
- onSubmit={(event) => {
- event.preventDefault();
- void save({ azureEndpoint: endpoint.trim(), azureDeployment: deployment.trim() });
- }}
- >
- <label className="flex flex-col gap-1.5">
- <span className="text-[13px] font-medium leading-[18px] text-ink">{t("call.live.azureEndpoint")}</span>
- <input
- type="url"
- inputMode="url"
- autoComplete="off"
- spellCheck={false}
- value={endpoint}
- placeholder="https://my-resource.openai.azure.com"
- onChange={(event) => setEndpoint(event.target.value)}
- className={FIELD}
- />
- </label>
- <label className="flex flex-col gap-1.5">
- <span className="text-[13px] font-medium leading-[18px] text-ink">{t("call.live.azureDeployment")}</span>
- <input
- type="text"
- autoComplete="off"
- spellCheck={false}
- value={deployment}
- placeholder="gpt-live-1"
- onChange={(event) => setDeployment(event.target.value)}
- className={FIELD}
- />
- </label>
- <div className="text-[12px] leading-4 text-ink-secondary">{t("call.live.azureHint")}</div>
- {azureChanged && (
- <button
- type="submit"
- disabled={saving || locked}
- className="ui-button ui-button-md self-end rounded-full"
- >
- {t("common.save")}
- </button>
- )}
- </form>
+ {(provider === "azure" || provider === "custom") && (
+ <EndpointForm key={provider} custom={provider === "custom"} live={live} disabled={saving || locked} save={save} />
)}
{provider === "fish" && <div className="text-[12px] leading-4 text-ink-secondary">{t("call.live.fishHint")}</div>}
{provider === "gemini" && <div className="text-[12px] leading-4 text-ink-secondary">{t("call.live.geminiHint")}</div>}
@@ -106,3 +62,58 @@ export function LiveProviderSettings({ locked = false, onSaving }: { locked?: bo
</div>
);
}
+
+/** The address and model name of an Azure resource, or of a custom OpenAI-compatible endpoint. */
+function EndpointForm({ custom, live, disabled, save }: { custom: boolean; live: LiveSettings; disabled: boolean; save: (patch: ProviderPatch) => Promise<void> }) {
+ const savedEndpoint = (custom ? live.customEndpoint : live.azureEndpoint) ?? "";
+ const savedModel = (custom ? live.customModel : live.azureDeployment) ?? "";
+ const [endpoint, setEndpoint] = useState(savedEndpoint);
+ const [model, setModel] = useState(savedModel);
+ const changed = endpoint.trim() !== savedEndpoint || model.trim() !== savedModel;
+
+ return (
+ <form
+ className="flex flex-col gap-2"
+ onSubmit={(event) => {
+ event.preventDefault();
+ void save(custom ? { customEndpoint: endpoint.trim(), customModel: model.trim() } : { azureEndpoint: endpoint.trim(), azureDeployment: model.trim() });
+ }}
+ >
+ <label className="flex flex-col gap-1.5">
+ <span className="text-[13px] font-medium leading-[18px] text-ink">{t(custom ? "call.live.customEndpoint" : "call.live.azureEndpoint")}</span>
+ <input
+ type="url"
+ inputMode="url"
+ autoComplete="off"
+ spellCheck={false}
+ value={endpoint}
+ placeholder={custom ? "https://gateway.example.com/v1" : "https://my-resource.openai.azure.com"}
+ onChange={(event) => setEndpoint(event.target.value)}
+ className={FIELD}
+ />
+ </label>
+ <label className="flex flex-col gap-1.5">
+ <span className="text-[13px] font-medium leading-[18px] text-ink">{t(custom ? "call.live.customModel" : "call.live.azureDeployment")}</span>
+ <input
+ type="text"
+ autoComplete="off"
+ spellCheck={false}
+ value={model}
+ placeholder="gpt-live-1"
+ onChange={(event) => setModel(event.target.value)}
+ className={FIELD}
+ />
+ </label>
+ <div className="text-[12px] leading-4 text-ink-secondary">{t(custom ? "call.live.customHint" : "call.live.azureHint")}</div>
+ {changed && (
+ <button
+ type="submit"
+ disabled={disabled}
+ className="ui-button ui-button-md self-end rounded-full"
+ >
+ {t("common.save")}
+ </button>
+ )}
+ </form>
+ );
+}
diff --git a/src/components/keys/KeysPage.dom.test.ts b/src/components/keys/KeysPage.dom.test.ts
index ce60dc5f7c..a55a014fd2 100644
--- a/src/components/keys/KeysPage.dom.test.ts
+++ b/src/components/keys/KeysPage.dom.test.ts
@@ -101,15 +101,28 @@ describe("the keys page", () => {
expect(rowsShown()).not.toContain("elevenlabs");
});
- it("offers the Live calls service, OpenAI, Azure OpenAI, Fish Audio, Gemini or ElevenLabs, on the separate live key row", () => {
+ it("offers the Live calls service, OpenAI, Azure OpenAI, Fish Audio, Gemini, ElevenLabs or a custom endpoint, on the separate live key row", () => {
setConfig({ ...fx.config, live: { configured: false, provider: "azure", voice: "", readTypedReplies: true, idleMinutes: 5 } });
page();
const select = row("liveKey")!.querySelector<HTMLSelectElement>("select")!;
- expect([...select.options].map((option) => option.value)).toEqual(["openai", "azure", "fish", "gemini", "elevenlabs"]);
+ expect([...select.options].map((option) => option.value)).toEqual(["openai", "azure", "fish", "gemini", "elevenlabs", "custom"]);
expect(select.value).toBe("azure");
expect(row("liveKey")!.querySelector('input[type="url"]')).not.toBeNull();
});
+ it("with a custom endpoint chosen, the Live key row asks for that endpoint's key, with its address and model, and no OpenAI page", () => {
+ const live = { configured: false, voice: "", readTypedReplies: true, idleMinutes: 5 };
+ setConfig({ ...fx.config, live: { ...live, provider: "custom", customEndpoint: "https://gateway.example.com/v1", customModel: "my-live" } });
+ page();
+ const custom = row("liveKey")!;
+ expect(custom.textContent).toContain("Custom endpoint key for Live calls");
+ expect(custom.textContent).toContain("Required");
+ expect(custom.querySelector<HTMLInputElement>('input[type="url"]')!.value).toBe("https://gateway.example.com/v1");
+ expect([...custom.querySelectorAll("input")].map((input) => input.value)).toContain("my-live");
+ expect(custom.querySelector<HTMLAnchorElement>('a[href*="platform.openai.com"]')).toBeNull();
+ expect(row("liveCalls")).toBeNull();
+ });
+
it("with Azure chosen, the Live key row asks for an Azure key: required, no OpenAI wording, and no row saying Live uses the OpenAI key", () => {
const live = { configured: false, voice: "", readTypedReplies: true, idleMinutes: 5 };
setConfig({ ...fx.config, live: { ...live, provider: "azure", azureEndpoint: "https://my-res.openai.azure.com" } });
diff --git a/src/components/keys/key-catalog.ts b/src/components/keys/key-catalog.ts
index db13a50891..448a2a5374 100644
--- a/src/components/keys/key-catalog.ts
+++ b/src/components/keys/key-catalog.ts
@@ -220,12 +220,12 @@ export function keyEntry(id: KeyId): KeyEntry {
return entry;
}
-/** With Azure OpenAI, Fish Audio, Gemini or ElevenLabs chosen for Live calls, the row for their key is about that service:
+/** With Azure OpenAI, a custom endpoint, Fish Audio, Gemini or ElevenLabs chosen for Live calls, the row for their key is about that service:
* required, and no OpenAI key. With Fish Audio, Gemini or ElevenLabs it is that service's key itself, which its voices use too. */
export function shownKeyEntry(id: KeyId, config: ConfigStatus | null | undefined): KeyEntry {
const entry = keyEntry(id);
const provider = config?.live?.provider;
- if (id !== "liveKey" || (provider !== "azure" && provider !== "fish" && provider !== "gemini" && provider !== "elevenlabs") || !entry.target) return entry;
+ if (id !== "liveKey" || (provider !== "azure" && provider !== "custom" && provider !== "fish" && provider !== "gemini" && provider !== "elevenlabs") || !entry.target) return entry;
const { shape: _openAiShape, ...target } = entry.target;
if (provider === "fish") {
return { ...entry, name: "Fish Audio", labelKey: "keys.label.fishAudio", purposeKey: "keys.purpose.liveKeyFish", target: keyEntry("fishAudio").target };
@@ -242,6 +242,10 @@ export function shownKeyEntry(id: KeyId, config: ConfigStatus | null | undefined
};
return { ...entry, name: "ElevenLabs", labelKey: "keys.label.elevenlabs", purposeKey: "keys.purpose.liveKeyElevenLabs", target: { ...voices, saved } };
}
+ if (provider === "custom") {
+ const { href: _openAiPage, ...own } = target;
+ return { ...entry, name: "Custom endpoint", labelKey: "call.live.customKeyField", purposeKey: "keys.purpose.liveKeyCustom", target: { ...own, placeholder: "…" } };
+ }
return { ...entry, name: "Azure OpenAI", labelKey: "call.live.azureKeyField", purposeKey: "keys.purpose.liveKeyAzure", target: { ...target, placeholder: "…", href: "https://portal.azure.com" } };
}
@@ -255,11 +259,11 @@ export function savedState(entry: KeyEntry, config: ConfigStatus | null | undefi
return entry.target?.saved(config) ?? entry.status?.(config) ?? { configured: false };
}
-/** With Azure, Fish Audio, Gemini or ElevenLabs chosen, Live calls do not use the OpenAI key the Live calls row points at, so that row is
+/** With Azure, a custom endpoint, Fish Audio, Gemini or ElevenLabs chosen, Live calls do not use the OpenAI key the Live calls row points at, so that row is
* hidden. */
export function keyHidden(id: KeyId, config: ConfigStatus | null | undefined): boolean {
const provider = config?.live?.provider;
- return id === "liveCalls" && (provider === "azure" || provider === "fish" || provider === "gemini" || provider === "elevenlabs");
+ return id === "liveCalls" && (provider === "azure" || provider === "custom" || provider === "fish" || provider === "gemini" || provider === "elevenlabs");
}
/** With `config`, the row is matched as shown: the Live key row by the provider Live calls use. */
diff --git a/src/lib/call-mode.ts b/src/lib/call-mode.ts
index 49b3372482..773ec29fc4 100644
--- a/src/lib/call-mode.ts
+++ b/src/lib/call-mode.ts
@@ -12,7 +12,8 @@ export const CALL_MODES: ReadonlyArray<{ id: CallMode; label: LocaleKey }> = [
{ id: "live", label: "call.mode.live" },
];
-export function liveDisclosure({ cloudHome = false, azure = false, fish = false, gemini = false, elevenlabs = false }: { cloudHome?: boolean; azure?: boolean; fish?: boolean; gemini?: boolean; elevenlabs?: boolean } = {}): string {
+export function liveDisclosure({ cloudHome = false, azure = false, custom = false, fish = false, gemini = false, elevenlabs = false }: { cloudHome?: boolean; azure?: boolean; custom?: boolean; fish?: boolean; gemini?: boolean; elevenlabs?: boolean } = {}): string {
+ if (custom) return t(cloudHome ? "call.live.disclosureCustomCloud" : "call.live.disclosureCustom");
if (azure) return t(cloudHome ? "call.live.disclosureAzureCloud" : "call.live.disclosureAzure");
if (fish) return t(cloudHome ? "call.live.disclosureFishCloud" : "call.live.disclosureFish");
if (gemini) return t(cloudHome ? "call.live.disclosureGeminiCloud" : "call.live.disclosureGemini");
@@ -20,11 +21,14 @@ export function liveDisclosure({ cloudHome = false, azure = false, fish = false,
return t(cloudHome ? "call.live.disclosureCloud" : "call.live.disclosure");
}
-/** The copy about a Live call's key: Azure, Fish Audio, Gemini and ElevenLabs need a key of their own, OpenAI can borrow the OpenAI key. */
+/** The copy about a Live call's key: Azure, a custom endpoint, Fish Audio, Gemini and ElevenLabs need a key of their own, OpenAI can borrow the OpenAI key. */
export function liveKeyCopy(provider: LiveProvider | undefined) {
if (provider === "azure") {
return { title: "call.live.azureKeyTitle", explain: "call.live.azureKeyExplain", field: "call.live.azureKeyField", key: "call.live.azureKey", missing: "call.live.azureNeedsKey", needs: "call.live.needsAzure", cost: "call.live.azureCost" } as const;
}
+ if (provider === "custom") {
+ return { title: "call.live.customKeyTitle", explain: "call.live.customKeyExplain", field: "call.live.customKeyField", key: "call.live.customKey", missing: "call.live.customNeedsKey", needs: "call.live.needsCustom", cost: "call.live.customCost" } as const;
+ }
if (provider === "fish") {
return { title: "call.live.fishKeyTitle", explain: "call.live.fishKeyExplain", field: "call.live.fishKeyField", key: "call.live.fishKey", missing: "call.live.fishNeedsKey", needs: "call.live.needsFish", cost: "call.live.fishCost" } as const;
}
diff --git a/src/locales/en.json b/src/locales/en.json
index b68de68e59..9fde5aaa30 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -6887,6 +6887,19 @@
"call.live.needsAzure": "Live calls through Azure OpenAI need the resource endpoint, the GPT-Live deployment name and its key.",
"call.live.disclosureAzure": "A Live call sends your voice to your Azure OpenAI resource, along with the chat's recent messages, the bot's answers and the details of any approval it asks for. The Azure key stays on your computer.",
"call.live.disclosureAzureCloud": "A Live call sends your voice to your Azure OpenAI resource, along with the chat's recent messages, the bot's answers and the details of any approval it asks for. The Azure key stays in the Cloud.",
+ "call.live.provider.custom": "Custom endpoint",
+ "call.live.customEndpoint": "Endpoint address",
+ "call.live.customModel": "Model",
+ "call.live.customHint": "Any server that speaks OpenAI's GPT-Live API (POST /v1/live/sessions), such as your own gateway. Paste its address, like https://gateway.example.com/v1, and the model name. An empty name means gpt-live-1. Plain http works only on this computer (127.0.0.1 or localhost). A key works only with the endpoint it was saved for: changing the Service or the endpoint's host asks for the key again.",
+ "call.live.customKey": "Endpoint key",
+ "call.live.customNeedsKey": "Add the key of your custom endpoint with Change key.",
+ "call.live.customKeyTitle": "Live calls through a custom endpoint",
+ "call.live.customKeyExplain": "Paste the key your custom endpoint accepts. It is sent only to that endpoint, as a bearer token. Whoever runs the endpoint bills the call; the bot's own work is billed as usual.",
+ "call.live.customKeyField": "Custom endpoint key for Live calls",
+ "call.live.customCost": "Via your custom endpoint, billed by whoever runs it.",
+ "call.live.needsCustom": "Live calls through a custom endpoint need its address and its key.",
+ "call.live.disclosureCustom": "A Live call sends your voice to your custom endpoint, along with the chat's recent messages, the bot's answers and the details of any approval it asks for. The endpoint's key stays on your computer.",
+ "call.live.disclosureCustomCloud": "A Live call sends your voice to your custom endpoint, along with the chat's recent messages, the bot's answers and the details of any approval it asks for. The endpoint's key stays in the Cloud.",
"call.live.provider.fish": "Fish Audio Live 3",
"call.live.fishHint": "Fish Audio Live 3 speaks English only. Its calls work in the desktop app and in a browser, for the owner of this computer.",
"call.live.fishKey": "Fish Audio key",
@@ -8073,6 +8086,7 @@
"keys.purpose.liveCalls": "Live calls use the same key as OpenAI's models",
"keys.purpose.liveKey": "Optional. Live calls use it instead of your OpenAI key",
"keys.purpose.liveKeyAzure": "Required. A key of the Azure resource your Live calls use",
+ "keys.purpose.liveKeyCustom": "Required. The key of the custom endpoint your Live calls use",
"keys.purpose.liveKeyFish": "Required. Live calls through Fish Audio use your Fish Audio key",
"keys.purpose.liveKeyGemini": "Required. Live calls through Gemini use your Gemini key",
"keys.purpose.liveKeyElevenLabs": "Required. Live calls through ElevenLabs use your ElevenLabs key",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index ed5bc36018..d102ee7fca 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -6565,6 +6565,19 @@
"call.live.needsAzure": "Chamadas ao vivo pelo Azure OpenAI precisam do endereço do recurso, do nome da implantação do GPT-Live e da chave do recurso.",
"call.live.disclosureAzure": "Uma chamada ao vivo envia sua voz para o recurso do Azure OpenAI, junto com as mensagens recentes da conversa, as respostas do bot e os detalhes de qualquer aprovação que ele pedir. A chave do Azure fica no seu computador.",
"call.live.disclosureAzureCloud": "Uma chamada ao vivo envia sua voz para o recurso do Azure OpenAI, junto com as mensagens recentes da conversa, as respostas do bot e os detalhes de qualquer aprovação que ele pedir. A chave do Azure fica no Cloud.",
+ "call.live.provider.custom": "Endereço personalizado",
+ "call.live.customEndpoint": "Endereço do serviço",
+ "call.live.customModel": "Modelo",
+ "call.live.customHint": "Qualquer servidor compatível com a API GPT-Live da OpenAI (POST /v1/live/sessions), como o seu próprio gateway. Cole o endereço, por exemplo https://gateway.example.com/v1, e o nome do modelo. Deixe o nome em branco para usar gpt-live-1. http simples só funciona neste computador (127.0.0.1 ou localhost). Uma chave só funciona com o endereço para o qual foi salva: ao mudar a opção “Serviço” ou o domínio do endereço, você precisa informar a chave novamente.",
+ "call.live.customKey": "Chave do serviço",
+ "call.live.customNeedsKey": "Adicione a chave do seu endereço personalizado pela opção “Trocar chave”.",
+ "call.live.customKeyTitle": "Chamadas ao vivo por um endereço personalizado",
+ "call.live.customKeyExplain": "Cole a chave que o seu endereço personalizado aceita. Ela é enviada só para esse endereço, como token bearer. Quem mantém o serviço cobra a chamada; o trabalho do próprio bot é cobrado normalmente.",
+ "call.live.customKeyField": "Chave do endereço personalizado para chamadas ao vivo",
+ "call.live.customCost": "Pelo seu endereço personalizado, com cobrança de quem mantém o serviço.",
+ "call.live.needsCustom": "Chamadas ao vivo por um endereço personalizado precisam do endereço e da chave.",
+ "call.live.disclosureCustom": "Uma chamada ao vivo envia sua voz para o seu endereço personalizado, junto com as mensagens recentes da conversa, as respostas do bot e os detalhes de qualquer aprovação que ele pedir. A chave do serviço fica no seu computador.",
+ "call.live.disclosureCustomCloud": "Uma chamada ao vivo envia sua voz para o seu endereço personalizado, junto com as mensagens recentes da conversa, as respostas do bot e os detalhes de qualquer aprovação que ele pedir. A chave do serviço fica no Cloud.",
"call.live.provider.fish": "Fish Audio Live 3",
"call.live.fishHint": "O Fish Audio Live 3 fala apenas inglês. As chamadas funcionam no app para computador e no navegador, para o dono deste computador.",
"call.live.fishKey": "Chave do Fish Audio",
@@ -7977,6 +7990,7 @@
"keys.purpose.liveCalls": "Chamadas ao vivo usam a mesma chave dos modelos da OpenAI",
"keys.purpose.liveKey": "Opcional. As chamadas ao vivo usam esta chave em vez da chave da OpenAI",
"keys.purpose.liveKeyAzure": "Obrigatória. Uma chave do recurso do Azure usado nas chamadas ao vivo",
+ "keys.purpose.liveKeyCustom": "Obrigatória. A chave do endereço personalizado usado nas chamadas ao vivo",
"keys.purpose.liveKeyFish": "Obrigatória. As chamadas ao vivo pelo Fish Audio usam sua chave do Fish Audio",
"keys.purpose.liveKeyGemini": "Obrigatória. As chamadas ao vivo pelo Gemini usam sua chave do Gemini",
"keys.purpose.liveKeyElevenLabs": "Obrigatória. As chamadas ao vivo pelo ElevenLabs usam sua chave do ElevenLabs",
diff --git a/src/locales/source-hashes.json b/src/locales/source-hashes.json
index 346866c61e..e995e8f0f6 100644
--- a/src/locales/source-hashes.json
+++ b/src/locales/source-hashes.json
@@ -36955,7 +36955,21 @@
"remote.diagnosis.next.otherCopy": "29f59104ac96620533eecfef5e6bd7e612e84c6b2a6f71ebdb02550d4cd3518e",
"devices.computers.pairButton": "60f8288e33f9f57d2b51409fdb540b47a89c25447061bd354122442818a36ee0",
"devices.computers.pairTitle": "b7cda6a11ab410daa4b8977624ca72261c0168e7c3d83ae0eed93ac4e3540bc8",
- "devices.computers.typeCode": "2a528dfe78f6b331e8cca951872961169ca6f340a886e40e84cc0b53d441c174"
+ "devices.computers.typeCode": "2a528dfe78f6b331e8cca951872961169ca6f340a886e40e84cc0b53d441c174",
+ "call.live.provider.custom": "5fb0795eaf2ee446b929b73b8c78d7c2c15d3aa3cbaf6cc1e5df78e855450393",
+ "call.live.customEndpoint": "be6c76aba07a7890baab87c3bd80c40ec66d1a63650e9e370bd4810adea7f80e",
+ "call.live.customModel": "5e2c614c23f02239bc03c6c04fcb681950f9e72bf8fdff6be79c79841cbb10c0",
+ "call.live.customHint": "7376f7551975b058627fb758e30fa552515707135492ff8efec57e46f42189b1",
+ "call.live.customKey": "f12176907a5b14c717e4f32560ea1b65c535271e7a484112aaa5511c1d3686eb",
+ "call.live.customNeedsKey": "f3a8a345177c5aaf2cb18b4cbe4ae195c54ba8a1108d03167a9537ae892721f3",
+ "call.live.customKeyTitle": "143a719a2fd736a4519678c901bfee45918b681c200a59f4e4318cc2ab3d27fd",
+ "call.live.customKeyExplain": "f4851a8cf42a27283a308feaca26c0b7b7f4acd1befedf7e49960279afb71bc7",
+ "call.live.customKeyField": "a7090a1486ef559b7e38467d904d45c7a96a45de158769c1e00499ed0f42b953",
+ "call.live.customCost": "de2a01497b1bdd6aff4d12e8a01bc607fb005e96e272ae77c8d6740e6853d8ef",
+ "call.live.needsCustom": "a55223cc78bd2411b92a1f544877599eae7e6815e67f5e0debf1d487bdbb7ae6",
+ "call.live.disclosureCustom": "cf9a25b5ed7e5bf386f9d8e7be6d0d713bc1d142e92d2cf6c663df5788ac6eb8",
+ "call.live.disclosureCustomCloud": "b789b3cd12e4647003e2f65e294c7e7790fcc3dbe06a77946c2ec7cab4e856c5",
+ "keys.purpose.liveKeyCustom": "8e99e704d8b7f385fcc744b307bb9d3e132a506bc3cdee57fc51941822fc745a"
},
"zh": {
"pro.fromPrice": "a48a04a457d60b08b54fc83e7a6c4584ffedb1e23621859084900c8521a3af7b",