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: allow verbose free chat tool schemas (#5318)

Ezra Ellette817800af8e8a
diff --git a/packages/ai-gateway/src/services/free-chat-limit.test.ts b/packages/ai-gateway/src/services/free-chat-limit.test.ts
index 9ce8d9d6d..67e5b5f94 100644
--- a/packages/ai-gateway/src/services/free-chat-limit.test.ts
+++ b/packages/ai-gateway/src/services/free-chat-limit.test.ts
@@ -17,8 +17,8 @@ import {
FREE_CHAT_MAX_RESPONSE_FORMAT_BYTES,
FREE_CHAT_MAX_STRUCTURE_DEPTH,
FREE_CHAT_MAX_TEXT_BYTES,
- FREE_CHAT_MAX_TOOL_BYTES,
FREE_CHAT_MAX_TOOLS,
+ FREE_CHAT_MAX_TOOLS_BYTES,
acquireFreeChatLease,
applyFreeChatRequestLimits,
prepareFreeChatTurn,
@@ -546,7 +546,7 @@ describe('validateFreeChatRequestLimits', () => {
expect(disguisedFile?.code).toBe('free_chat_image_unverifiable');
});
- it('caps tool count and each serialized schema', () => {
+ it('caps tool count and aggregate schema bytes without rejecting one verbose tool', () => {
const tool = { type: 'function', function: { name: 'tool', description: 'x', parameters: { type: 'object', properties: {} } } };
const tooMany = validateFreeChatRequestLimits({
...bodyWith([{ role: 'user', content: 'hello' }]),
@@ -554,11 +554,17 @@ describe('validateFreeChatRequestLimits', () => {
}, preview);
expect(tooMany?.code).toBe('free_chat_too_many_tools');
- const oversized = validateFreeChatRequestLimits({
+ const verboseTool = validateFreeChatRequestLimits({
...bodyWith([{ role: 'user', content: 'hello' }]),
- tools: [{ ...tool, function: { ...tool.function, description: 'x'.repeat(FREE_CHAT_MAX_TOOL_BYTES) } }],
+ tools: [{ ...tool, function: { ...tool.function, description: 'x'.repeat(32 * 1024) } }],
}, preview);
- expect(oversized?.code).toBe('free_chat_tool_too_large');
+ expect(verboseTool).toBeNull();
+
+ const oversizedTotal = validateFreeChatRequestLimits({
+ ...bodyWith([{ role: 'user', content: 'hello' }]),
+ tools: [{ ...tool, function: { ...tool.function, description: 'x'.repeat(FREE_CHAT_MAX_TOOLS_BYTES) } }],
+ }, preview);
+ expect(oversizedTotal?.code).toBe('free_chat_tools_too_large');
});
it('rejects malformed tools and assistant tool calls before provider dispatch', () => {
diff --git a/packages/ai-gateway/src/services/free-chat-limit.ts b/packages/ai-gateway/src/services/free-chat-limit.ts
index fcb588aea..8be938bb0 100644
--- a/packages/ai-gateway/src/services/free-chat-limit.ts
+++ b/packages/ai-gateway/src/services/free-chat-limit.ts
@@ -15,7 +15,6 @@ export const FREE_CHAT_MAX_TEXT_BYTES = 64 * 1024;
export const FREE_CHAT_MAX_IMAGES = 4;
export const FREE_CHAT_MAX_IMAGE_BYTES = 2 * 1024 * 1024;
export const FREE_CHAT_MAX_TOOLS = 48;
-export const FREE_CHAT_MAX_TOOL_BYTES = 16 * 1024;
export const FREE_CHAT_MAX_TOOLS_BYTES = 96 * 1024;
export const FREE_CHAT_MAX_RESPONSE_FORMAT_BYTES = 16 * 1024;
export const FREE_CHAT_MAX_STRUCTURE_DEPTH = 32;
@@ -323,12 +322,6 @@ export function validateFreeChatRequestBodyLimits(
`Free hosted chat tool definitions are limited to ${FREE_CHAT_MAX_TOOLS_BYTES} bytes per request.`,
);
}
- if (tools.some((tool) => jsonByteLength(tool) > FREE_CHAT_MAX_TOOL_BYTES)) {
- return requestTooLarge(
- 'free_chat_tool_too_large',
- `Each free hosted chat tool definition is limited to ${FREE_CHAT_MAX_TOOL_BYTES} bytes.`,
- );
- }
if (
body.response_format !== undefined
&& jsonByteLength(body.response_format) > FREE_CHAT_MAX_RESPONSE_FORMAT_BYTES