Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(ai-gateway): clamp reasoning_effort for GPT-5.4 function tools (#6863)

Ezra Ellettef51bc920e046
diff --git a/packages/ai-gateway/src/providers/openai.ts b/packages/ai-gateway/src/providers/openai.ts
index 8b742d8b2..661d65c5d 100644
--- a/packages/ai-gateway/src/providers/openai.ts
+++ b/packages/ai-gateway/src/providers/openai.ts
@@ -368,12 +368,13 @@ export class OpenAIProvider implements AIProvider {
}
private applyToolCompatibilityOptions(params: ChatCompletionCreateParams, body: RequestBody): void {
- // GPT-5.5 and GPT-5.6 accept function tools through Chat Completions only when
- // reasoning_effort is "none". Pi speaks the Chat Completions protocol,
- // so preserve tool support there rather than silently cascading a Luna
- // request to another provider. Agentic callers that need reasoning plus
- // tools can use the Responses API directly.
- if (/^gpt-5\.(?:5|6)(?:$|[.-])/i.test(body.model) && Array.isArray(body.tools) && body.tools.length > 0) {
+ // The whole GPT-5 family accepts function tools through Chat Completions
+ // only when reasoning_effort is "none" — including the 5.4 tier, which
+ // background pipes reach with an injected effort (applyBackgroundReasoningDefault).
+ // Pi speaks the Chat Completions protocol, so preserve tool support here
+ // rather than silently cascading the request to another provider. Agentic
+ // callers that need reasoning plus tools can use the Responses API directly.
+ if (/^gpt-5(?:$|[.-])/i.test(body.model) && Array.isArray(body.tools) && body.tools.length > 0) {
Object.assign(params, { reasoning_effort: 'none' });
}
}
diff --git a/packages/ai-gateway/src/test/provider-usage.unit.test.ts b/packages/ai-gateway/src/test/provider-usage.unit.test.ts
index a450c0aab..2479bc218 100644
--- a/packages/ai-gateway/src/test/provider-usage.unit.test.ts
+++ b/packages/ai-gateway/src/test/provider-usage.unit.test.ts
@@ -140,6 +140,28 @@ describe('OpenAIProvider usage reporting', () => {
expect(calls[0].reasoning_effort).toBe('none');
});
+ // Regression for the top ai-proxy 400 (47k events, all model:gpt-5.4-nano):
+ // background pipes get reasoning_effort injected by
+ // applyBackgroundReasoningDefault, and the 5.4 tier rejects function tools
+ // unless that effort is "none" — same Chat Completions rule as 5.5/5.6.
+ it('sets reasoning_effort to none for GPT-5.4 function tools with an injected background effort', async () => {
+ const { provider, calls } = makeOpenAIProvider(async () => ({
+ choices: [{ message: { content: 'answer', role: 'assistant' } }],
+ }));
+ const tools: any = [{
+ type: 'function',
+ function: {
+ name: 'search_screenpipe',
+ parameters: { type: 'object', properties: {} },
+ },
+ }];
+
+ await provider.createCompletion({ ...body, model: 'gpt-5.4-nano', reasoning_effort: 'low', tools });
+
+ expect(calls).toHaveLength(1);
+ expect(calls[0].reasoning_effort).toBe('none');
+ });
+
it('does not disable reasoning for GPT-5.6 requests without tools', async () => {
async function* stream() {
yield { choices: [{ delta: { content: 'ok' }, finish_reason: 'stop' }] };