The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.
TypeScript ai-receptionistanswering-serviceappointment-bookinglivekitlocal-firstmcpopen-sourceself-hostedsiptelephonytypescriptvoice-agentvoice-ai
OpenAI: no OpenRouter fallback list on calls with the assistant's own model (PR 2053)
Janik153fe5304985
diff --git a/apps/agent/src/config.test.ts b/apps/agent/src/config.test.tsindex 7d388346..f0edb42f 100644--- a/apps/agent/src/config.test.ts+++ b/apps/agent/src/config.test.ts@@ -586,10 +586,10 @@ test('a call test may use another realtime model; the three stages and other cal})describe("withAssistantModel: the assistant's own language model (usage levels)", () => {- test("a listed model of the install's provider goes first, the install's model after it as a fallback", () => {+ test("a listed model of the install's provider goes first; OpenAI gets no fallbacks (it refuses `models`)", () => {const config = resolveCallConfig(stored, {})const own = stagesOf(withAssistantModel(config, 'gpt-4.1'))!- expect(own.llm).toMatchObject({ provider: 'openai', model: 'gpt-4.1', fallbacks: ['gpt-4.1-mini'] })+ expect(own.llm).toMatchObject({ provider: 'openai', model: 'gpt-4.1', fallbacks: [] })// The summary model stays the install's.expect(own.llm.summaryModel).toBe(stagesOf(config)!.llm.summaryModel)})diff --git a/apps/agent/src/config.ts b/apps/agent/src/config.tsindex da0f0328..82b3bf1e 100644--- a/apps/agent/src/config.ts+++ b/apps/agent/src/config.ts@@ -396,18 +396,18 @@ export const withAssistantRealtimeVoice = (/*** The config with the assistant's own language model (`assistants.llm_model`, Settings › Assistant › Voice) for live- * turns, when the install's provider serves it (languageModelFor); else the install's model. OpenRouter keeps the- * install's fallbacks after it. The summary model stays the install's.+ * turns, when the install's provider serves it (languageModelFor); else the install's model. Only OpenRouter keeps+ * the install's model and fallbacks after it. The summary model stays the install's.*/export function withAssistantModel(config: CallConfig, llmModel: string | null | undefined): CallConfig {const stages = stagesOf(config)if (!stages) return configconst model = languageModelFor(stages.llm.provider, llmModel, stages.llm.model)if (model === stages.llm.model) return config- const own: AgentConfig = {- ...stages,- llm: { ...stages.llm, model, fallbacks: [stages.llm.model, ...stages.llm.fallbacks].filter(m => m !== model) },- }+ // Only OpenRouter takes a fallback list (`models`); OpenAI and the others refuse the request with it (400).+ const fallbacks =+ stages.llm.provider === 'openrouter' ? [stages.llm.model, ...stages.llm.fallbacks].filter(m => m !== model) : []+ const own: AgentConfig = { ...stages, llm: { ...stages.llm, model, fallbacks } }return isRealtime(config) ? { ...config, stages: own } : own}diff --git a/apps/agent/src/pipeline.test.ts b/apps/agent/src/pipeline.test.tsindex b1d53f5e..ae72b95c 100644--- a/apps/agent/src/pipeline.test.ts+++ b/apps/agent/src/pipeline.test.ts@@ -445,6 +445,10 @@ test('every conversation request is capped, with OpenRouter fallbacks as `modelsexpect(replyRequestFields('gpt-5.4', [], 'https://api.openai.com/v1')).toEqual({max_completion_tokens: REPLY_MAX_TOKENS,})+ // Fallbacks never reach OpenAI: it refuses `models` with a 400.+ expect(replyRequestFields('gpt-5.4', ['gpt-4.1-mini'], 'https://api.openai.com/v1')).toEqual({+ max_completion_tokens: REPLY_MAX_TOKENS,+ })})test('Flux stays for calls in its 10 languages; any other language takes Nova-3 multi with Deepgram hints', () => {diff --git a/apps/agent/src/pipeline.ts b/apps/agent/src/pipeline.tsindex 0d09bdb8..982ad567 100644--- a/apps/agent/src/pipeline.ts+++ b/apps/agent/src/pipeline.ts@@ -7,6 +7,7 @@import {DEFAULT_VOICE_MODELS,noPrivateEndpointText,+ isOpenRouterUrl,noTrainingFields,voiceModelFor,anyModeLanguages,@@ -475,8 +476,12 @@ export const talkingSpeedOf = (assistant: TalkingSpeedFields | null | undefined)return paceCorrectedPct(pct, voice?.voice_id || defaultVoiceFor('elevenlabs', language), language)}-/** OpenRouter's `models`: the model first, then the ones it tries when that one fails. */-const modelsField = (model: string, fallbacks: string[]) => (fallbacks.length ? { models: [model, ...fallbacks] } : {})+/**+ * OpenRouter's `models`: the model first, then the ones it tries when that one fails. Only to OpenRouter: OpenAI and+ * the other APIs refuse a request with it (400 "Unrecognized request argument supplied: models").+ */+const modelsField = (baseUrl: string, model: string, fallbacks: string[]) =>+ fallbacks.length && isOpenRouterUrl(baseUrl) ? { models: [model, ...fallbacks] } : {}/*** A cap on the answer's tokens. OpenAI's own API wants `max_completion_tokens` (its gpt-5 models refuse `max_tokens`@@ -492,7 +497,7 @@ export const tokenCap = (baseUrl: string, n: number) =>*/export const replyRequestFields = (model: string, fallbacks: string[], baseUrl: string, zeroDataRetention = true) => ({...tokenCap(baseUrl, REPLY_MAX_TOKENS),- ...modelsField(model, fallbacks),+ ...modelsField(baseUrl, model, fallbacks),...noTrainingFields(baseUrl, zeroDataRetention),})@@ -853,7 +858,7 @@ export function chatJson(chat: ChatModel, doFetch: typeof fetch = fetch, timeoutheaders: { 'content-type': 'application/json', authorization: `Bearer ${apiKey}` },body: JSON.stringify({model,- ...modelsField(model, fallbacks),+ ...modelsField(baseUrl, model, fallbacks),...noTrainingFields(baseUrl, zeroDataRetention),response_format: { type: 'json_object' },...tokenCap(baseUrl, SUMMARY_MAX_TOKENS),