Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

fix(onomeo): reject substituted model identities (#1694)

Tashfeen5646971602a8
diff --git a/server/src/__tests__/services/onomeo.test.ts b/server/src/__tests__/services/onomeo.test.ts
index d5fbf207..69c631f0 100644
--- a/server/src/__tests__/services/onomeo.test.ts
+++ b/server/src/__tests__/services/onomeo.test.ts
@@ -63,6 +63,48 @@ describe('onomeo key validation', () => {
});
describe('onomeo chat', () => {
+ it.each(['glm-5.2', undefined, '', null, 123])('rejects a substituted or missing completion identity (%s)', async model => {
+ vi.spyOn(global, 'fetch').mockResolvedValue(json({ ...completion(), model }));
+ await expect(new OnomeoProvider().chatCompletion('test-key', [], 'deepseek-v4-flash'))
+ .rejects.toMatchObject({ status: 502, message: 'onomeo returned a different or missing model identity' });
+ });
+
+ it.each(['glm-5.2', undefined, '', null])('rejects a stream identity (%s) before emitting any content', async model => {
+ const frame = { id: 'c', object: 'chat.completion.chunk', created: 1, model,
+ choices: [{ index: 0, delta: { role: 'assistant', content: 'Wrong answer', tool_calls: [] }, finish_reason: null }] };
+ vi.spyOn(global, 'fetch').mockResolvedValue(new Response(`data: ${JSON.stringify(frame)}\n\ndata: [DONE]\n\n`, {
+ headers: { 'content-type': 'text/event-stream' },
+ }));
+ const stream = new OnomeoProvider().streamChatCompletion('test-key', [], 'deepseek-v4-flash');
+ await expect(stream.next()).rejects.toMatchObject({ status: 502 });
+ });
+
+ it('rejects identity changes in later stream frames without leaking their content', async () => {
+ const frames = ['glm-4.5-flash', 'glm-5.2'].map(model => `data: ${JSON.stringify({
+ id: 'c', object: 'chat.completion.chunk', created: 1, model,
+ choices: [{ index: 0, delta: { content: model }, finish_reason: null }],
+ })}\n\n`);
+ vi.spyOn(global, 'fetch').mockResolvedValue(new Response(frames.join('') + 'data: [DONE]\n\n', {
+ headers: { 'content-type': 'text/event-stream' },
+ }));
+ const stream = new OnomeoProvider().streamChatCompletion('test-key', [], 'glm-4.5-flash');
+ expect((await stream.next()).value?.choices[0].delta.content).toBe('glm-4.5-flash');
+ await expect(stream.next()).rejects.toMatchObject({ status: 502 });
+ });
+
+ it('preserves tool-call frames with an exact identity, including a namespaced route', async () => {
+ const model = 'stealth/glyph-cluster';
+ const tool_calls = [{ index: 0, id: 'call_1', type: 'function', function: { name: 'lookup', arguments: '{}' } }];
+ const frame = { id: 'c', object: 'chat.completion.chunk', created: 1, model,
+ choices: [{ index: 0, delta: { tool_calls }, finish_reason: 'tool_calls' }] };
+ vi.spyOn(global, 'fetch').mockResolvedValue(new Response(`data: ${JSON.stringify(frame)}\n\ndata: [DONE]\n\n`, {
+ headers: { 'content-type': 'text/event-stream' },
+ }));
+ const stream = new OnomeoProvider().streamChatCompletion('test-key', [], model);
+ expect((await stream.next()).value).toMatchObject(frame);
+ expect((await stream.next()).done).toBe(true);
+ });
+
it('forwards OpenAI-shape completions with attribution', async () => {
const fetch = vi.spyOn(global, 'fetch').mockResolvedValue(json(completion('glm-5.3')));
const result = await new OnomeoProvider().chatCompletion('test-key', [{ role: 'user', content: 'Hi' }], 'glm-5.3', { max_tokens: 512 });
diff --git a/server/src/providers/onomeo.ts b/server/src/providers/onomeo.ts
index 755d8822..587c652f 100644
--- a/server/src/providers/onomeo.ts
+++ b/server/src/providers/onomeo.ts
@@ -5,6 +5,14 @@ import { OpenAICompatProvider } from './openai-compat.js';
export const ONOMEO_BASE_URL = 'https://onomeo.com/v1';
+// Retired IDs can return HTTP 200 with a different model (observed 2026-10-24).
+// Fail over instead of attributing that answer to the requested catalog route.
+function checkModelIdentity(requested: string, returned: unknown): void {
+ if (typeof returned !== 'string' || !returned || returned !== requested) {
+ throw Object.assign(new Error('onomeo returned a different or missing model identity'), { status: 502 });
+ }
+}
+
// Free-tier answers end with this line (verified live 2026-10-21: every text
// reply, streamed as its own final delta "\n\n— via onomeo.com"; tool-call
// turns carry none). It is provider branding, not model output, so it must not
@@ -66,6 +74,7 @@ export class OnomeoProvider extends OpenAICompatProvider {
options?: CompletionOptions, quotaContext?: QuotaObservationContext,
): Promise<ChatCompletionResponse> {
const response = await super.chatCompletion(apiKey, messages, modelId, options, quotaContext);
+ checkModelIdentity(modelId, response.model);
for (const choice of response.choices ?? []) {
if (typeof choice.message?.content === 'string') {
choice.message.content = stripOnomeoSignature(choice.message.content);
@@ -83,6 +92,9 @@ export class OnomeoProvider extends OpenAICompatProvider {
let held = '';
let lastChunk: ChatCompletionChunk | null = null;
for await (const chunk of super.streamChatCompletion(apiKey, messages, modelId, options, quotaContext)) {
+ // Check every frame, including role/tool/finish frames, before yielding
+ // or retaining any of its content. Never rewrite the upstream identity.
+ checkModelIdentity(modelId, chunk.model);
lastChunk = chunk;
const delta = chunk.choices?.[0]?.delta;
if (typeof delta?.content !== 'string') {