Agent: OpenAI-style servers other than OpenAI get no "store" field, so Gemini answers (#5903)

A Gemini model added as an OpenAI-compatible connection failed with 400 "Invalid
JSON payload received. Unknown name "store"": the Harness's OpenAI client (pi-ai)
sends store: false to every OpenAI-style server it does not know as non-standard
(generativelanguage.googleapis.com is not on its list), and Google refuses unknown
fields. "store" is OpenAI's own field; the profile now gives every OpenAI-style
connection whose address is not api.openai.com compat.supportsStore false (the
same setting a server on this PC or network already had). OpenAI keeps pi-ai's
own choice; OpenRouter keeps its thinking format; Responses and Anthropic
connections are unchanged.
Test: tests/agent-store-field.test.mjs (fails on adafc50b5, passes); agent-shape's
cloud-route assertion now checks the thinking vocabulary it is about; profile
tests 51/51. Not run: a credentialed Gemini request.
This commit is contained in:
Niko1221 committed 2026-11-16 14:50:51 +01:00
1 parent 3c503be7a2
commit 9e4ef7ee88
3 files changed
+47 -2

No files matched your search

+11 -1
View File
@@ -202,6 +202,16 @@ export function outputBudget(context, maxOutput = null) {
* @returns {{patch:string, env:Record<string,string>, routes:Array, defaultRoute:object|null, signature:string}}
*/
/** What a local model, or an OpenAI-style server on this network, takes for the thinking level (see the comment where a local route is built). */
/**
* "store" is OpenAI's own field (keep the request out of its stored completions). pi-ai sends store: false to every OpenAI-style server it
* does not know as non-standard, and some refuse an unknown field: Google's Gemini endpoint answers 400 "Unknown name \"store\"" (#5903). Only
* OpenAI's own address gets it; for every other address it is left out.
*/
function storeCompat(baseURL) {
let host = '';
try { host = new URL(baseURL).hostname.toLowerCase(); } catch { /* not an address: leave it out */ }
return host === 'api.openai.com' ? {} : { supportsStore: false };
}
const THINKING_COMPAT = { supportsStore: false, thinkingFormat: 'chat-template', chatTemplateKwargs: { enable_thinking: { $var: 'thinking.enabled' }, reasoning_effort: { $var: 'thinking.effort', omitWhenOff: true } } };
export function buildProfile({ local = [], connections = [], gate = true, tools = NO_TOOLS_SETTINGS, skillsDir = null, proxyBase = null, searchMock = null, defaultLocalId = null }) {
@@ -282,7 +292,7 @@ export function buildProfile({ local = [], connections = [], gate = true, tools
api: protocol,
baseURL,
...(conn.apiKey || keyless ? { apiKeyEnv: keyEnv } : {}),
...(ownServer ? { compat: THINKING_COMPAT } : openRouter ? { compat: { thinkingFormat: 'openrouter' } } : {}),
...(ownServer ? { compat: THINKING_COMPAT } : openRouter ? { compat: { thinkingFormat: 'openrouter', ...storeCompat(baseURL) } } : protocol === 'openai-completions' ? { compat: storeCompat(baseURL) } : {}),
models: conn.models.map(m => ({
id: m.id, name: m.name || m.id,
contextWindow: m.contextMax ?? ASSUMED_API_CONTEXT, maxTokens: reply(m),
+1 -1
View File
@@ -54,7 +54,7 @@ test('the profile adds a response-settings copy of each shapeable route (local,
const providers = doc.find(e => e.id === 'llm-pi-ai').config.providers;
assert.equal(providers['api-lan'].compat.thinkingFormat, 'chat-template', 'a model server on this network gets the thinking vocabulary of a local model');
assert.equal(providers['api-lan'].models[0].reasoning, true);
assert.equal(providers['api-cloud'].compat, undefined, 'a cloud service does not');
assert.equal(providers['api-cloud'].compat?.thinkingFormat, undefined, 'a cloud service does not'); // (it may say "no store" field: #5903)
const small = buildProfile({ local: [], connections: [{ id: 'own', name: 'Own', baseUrl: 'http://127.0.0.1:18798/v1', protocol: 'openai-chat', apiKey: '', models: [{ id: 'm', contextMax: 32768 }] }] });
const own = JSON.parse(small.patch.slice(small.patch.indexOf('['))).find(e => e.id === 'llm-pi-ai').config.providers['api-own'];
assert.equal(own.models[0].maxTokens, 9830, 'a server on this network keeps 30 percent of its window for the reply so long tasks can be compacted (it was 28672 of 32768: no room, no compaction)');
@@ -0,0 +1,35 @@
// #5903: a Gemini model added as an OpenAI-compatible connection failed with 400 "Invalid JSON payload received. Unknown name \"store\"":
// the Harness's OpenAI client (pi-ai) sends store: false to every OpenAI-style server it does not know as non-standard, and Google's
// endpoint refuses unknown fields. "store" is OpenAI's own; the profile now tells pi-ai to leave it out for every other address.
import test from 'node:test';
import assert from 'node:assert/strict';
import { buildProfile } from '../server/agent/profile.mjs';
const providersOf = profile => {
const out = {};
const walk = v => { if (Array.isArray(v)) v.forEach(walk); else if (v && typeof v === 'object') { if (typeof v.api === 'string' && 'baseURL' in v) out[v.baseURL] = v; Object.values(v).forEach(walk); } };
walk(JSON.parse(profile.patch.split('\n').slice(1).join('\n')));
return out;
};
const conn = (id, baseUrl, protocol = 'openai-chat') => ({ id, name: id, baseUrl, protocol, apiKey: 'k', models: [{ id: 'm', name: 'm', contextMax: 131072 }] });
test('Gemini and other OpenAI-style servers get no "store"; OpenAI keeps it', () => {
const p = providersOf(buildProfile({ local: [], connections: [
conn('gemini', 'https://generativelanguage.googleapis.com/v1beta/openai'),
conn('openai', 'https://api.openai.com/v1'),
conn('other', 'https://api.example-llm.com/v1'),
conn('router', 'https://openrouter.ai/api/v1'),
] }));
assert.equal(p['https://generativelanguage.googleapis.com/v1beta/openai'].compat?.supportsStore, false, 'the reporter\'s Gemini endpoint');
assert.equal(p['https://api.example-llm.com/v1'].compat?.supportsStore, false);
assert.equal(p['https://api.openai.com/v1'].compat?.supportsStore, undefined, 'OpenAI: pi-ai\'s own choice, as before');
assert.deepEqual(p['https://openrouter.ai/api/v1'].compat, { thinkingFormat: 'openrouter', supportsStore: false }, 'OpenRouter keeps its thinking format');
});
test('the Responses and Anthropic protocols are left as they were', () => {
const p = providersOf(buildProfile({ local: [], connections: [
conn('resp', 'https://api.example-llm.com/v1', 'openai-responses'),
conn('anth', 'https://api.anthropic.com/v1', 'anthropic'),
] }));
for (const v of Object.values(p)) assert.equal(v.compat, undefined, v.baseURL);
});