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(gateway): param-policy tuning from the live all-provider sweep (#519)

Tashfeena9a0f319ff92
diff --git a/server/src/__tests__/lib/sampling-params.test.ts b/server/src/__tests__/lib/sampling-params.test.ts
index e26937ca..cd64e920 100644
--- a/server/src/__tests__/lib/sampling-params.test.ts
+++ b/server/src/__tests__/lib/sampling-params.test.ts
@@ -103,3 +103,29 @@ describe('supportedParametersFor / supportedParametersForPlatforms', () => {
expect(supportedParametersForPlatforms(['groq'])).toEqual(supportedParametersFor('groq'));
});
});
+
+describe('live-sweep policy findings (2026-07-11 demo-box validation)', () => {
+ it('kilo: response_format dropped (gateway 400s on it), seed still forwarded', () => {
+ const body = extendedBodyParams('kilo', { seed: 7, response_format: { type: 'json_object' } });
+ expect(body.seed).toBe(7);
+ expect(body).not.toHaveProperty('response_format');
+ });
+
+ it('reka: json_object upgraded to a permissive json_schema on the wire', () => {
+ const body = extendedBodyParams('reka', { response_format: { type: 'json_object' } });
+ expect((body.response_format as any).type).toBe('json_schema');
+ expect((body.response_format as any).json_schema.schema).toEqual({ type: 'object' });
+ });
+
+ it('reka: an explicit json_schema passes through untouched', () => {
+ const rf = { type: 'json_schema' as const, json_schema: { name: 'x', schema: { type: 'object', properties: {} } } };
+ const body = extendedBodyParams('reka', { response_format: rf });
+ expect(body.response_format).toBe(rf);
+ });
+
+ it('kilo is skipped by structured-output routing; reka is not', async () => {
+ const { platformDropsResponseFormat } = await import('../../lib/sampling-params.js');
+ expect(platformDropsResponseFormat('kilo')).toBe(true);
+ expect(platformDropsResponseFormat('reka')).toBe(false);
+ });
+});
diff --git a/server/src/lib/sampling-params.ts b/server/src/lib/sampling-params.ts
index 02cce9a9..9e39dc49 100644
--- a/server/src/lib/sampling-params.ts
+++ b/server/src/lib/sampling-params.ts
@@ -111,6 +111,11 @@ export function pickSamplingParams(body: ParsedSamplingBody): ExtendedSamplingOp
export interface PlatformParamPolicy {
drop?: readonly ExtendedSamplingKey[];
rename?: Readonly<Partial<Record<ExtendedSamplingKey, string>>>;
+ // The platform supports json_schema but 400s on json_object (observed live:
+ // Reka — "Unsupported response_format type: 'json_object'. Supported types
+ // are 'text' and 'json_schema'."). Upgrade json_object to a permissive
+ // json_schema on the wire instead of dropping structured output entirely.
+ jsonObjectToSchema?: boolean;
}
export const PLATFORM_PARAM_POLICIES: Record<string, PlatformParamPolicy> = {
@@ -137,6 +142,20 @@ export const PLATFORM_PARAM_POLICIES: Record<string, PlatformParamPolicy> = {
cloudflare: { drop: ['min_p', 'logit_bias', 'logprobs', 'top_logprobs'] },
// AI Horde builds its own payload format; none of the extended set maps.
aihorde: { drop: [...EXTENDED_SAMPLING_KEYS] },
+ // Kilo's anonymous gateway 400s ("Provider returned error") whenever
+ // response_format is present — observed live 2026-07-11; seed passes fine.
+ // Dropping it also makes structured-output routing skip kilo entirely.
+ kilo: { drop: ['response_format'] },
+ // Reka supports json_schema but rejects json_object (live 2026-07-11);
+ // upgraded on the wire instead of dropped.
+ reka: { jsonObjectToSchema: true },
+};
+
+// The permissive schema a json_object request is upgraded to on platforms
+// that only accept json_schema (any JSON object satisfies it).
+const ANY_OBJECT_SCHEMA = {
+ type: 'json_schema' as const,
+ json_schema: { name: 'json_output', schema: { type: 'object' } },
};
/**
@@ -151,8 +170,12 @@ export function extendedBodyParams(platform: string, options: ExtendedSamplingOp
const out: Record<string, unknown> = {};
for (const key of EXTENDED_SAMPLING_KEYS) {
if (dropped.has(key)) continue;
- const value = (options as Record<string, unknown>)[key];
+ let value = (options as Record<string, unknown>)[key];
if (value === undefined) continue;
+ if (key === 'response_format' && policy?.jsonObjectToSchema
+ && (value as { type?: string }).type === 'json_object') {
+ value = ANY_OBJECT_SCHEMA;
+ }
out[policy?.rename?.[key] ?? key] = value;
}
return out;