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): report hosted AI trial metadata (#5861)

Ezra Elletteb68dbc6f4fd6
diff --git a/packages/ai-gateway/src/services/cloudflare-ai-gateway.ts b/packages/ai-gateway/src/services/cloudflare-ai-gateway.ts
index 971bf8a7e..a156c5ef3 100644
--- a/packages/ai-gateway/src/services/cloudflare-ai-gateway.ts
+++ b/packages/ai-gateway/src/services/cloudflare-ai-gateway.ts
@@ -16,6 +16,7 @@ export interface HostedChatGatewayContext {
plan: HostedChatPlan;
lane: HostedChatLane;
workload: HostedChatWorkload;
+ trial: boolean;
}
export interface HostedChatGatewayConnection {
@@ -86,7 +87,7 @@ async function sha256Hex(value: string): Promise<string> {
return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('');
}
-/** Build the only four metadata fields Cloudflare receives. No prompt data is included. */
+/** Build the five reviewed metadata fields Cloudflare receives. No prompt data is included. */
export async function buildHostedChatGatewayContext(
auth: AuthResult,
model: string,
@@ -105,6 +106,7 @@ export async function buildHostedChatGatewayContext(
plan: collapsePlan(auth),
lane: model.toLowerCase() === 'auto' ? 'auto' : 'explicit',
workload,
+ trial: auth.hostedAiTrial === true,
};
}
diff --git a/packages/ai-gateway/src/test/cloudflare-ai-gateway.unit.test.ts b/packages/ai-gateway/src/test/cloudflare-ai-gateway.unit.test.ts
index c9db2c593..6c58323d3 100644
--- a/packages/ai-gateway/src/test/cloudflare-ai-gateway.unit.test.ts
+++ b/packages/ai-gateway/src/test/cloudflare-ai-gateway.unit.test.ts
@@ -32,7 +32,7 @@ describe('Cloudflare hosted-chat metadata', () => {
expect(getHostedChatGatewayMode({ HOSTED_CHAT_GATEWAY_MODE: 'CLOUDFLARE' })).toBe('cloudflare');
});
- it('hashes the account identity and sends only the four reviewed fields', async () => {
+ it('hashes the account identity and sends only the five reviewed fields', async () => {
const first = await buildHostedChatGatewayContext(auth(), 'auto', 'interactive');
const second = await buildHostedChatGatewayContext(
auth({ deviceId: 'different-device' }),
@@ -44,8 +44,8 @@ describe('Cloudflare hosted-chat metadata', () => {
expect(first.user_id).toMatch(/^[a-f0-9]{64}$/);
expect(JSON.stringify(first)).not.toContain('account-123');
expect(JSON.stringify(first)).not.toContain('device-secret');
- expect(Object.keys(first).sort()).toEqual(['lane', 'plan', 'user_id', 'workload']);
- expect(first).toMatchObject({ plan: 'basic', lane: 'auto', workload: 'interactive' });
+ expect(Object.keys(first).sort()).toEqual(['lane', 'plan', 'trial', 'user_id', 'workload']);
+ expect(first).toMatchObject({ plan: 'basic', lane: 'auto', workload: 'interactive', trial: false });
});
it('preserves Max and Ultra allowance tiers while collapsing catalog-equivalent plans', async () => {
@@ -58,9 +58,9 @@ describe('Cloudflare hosted-chat metadata', () => {
expect(context).toMatchObject({ plan: accountPlan, lane: 'auto', workload: 'background' });
}
const trial = await buildHostedChatGatewayContext(auth({ accountPlan: 'basic', hostedAiTrial: true }), 'auto', 'interactive');
- expect(trial.plan).toBe('basic');
+ expect(trial).toMatchObject({ plan: 'basic', trial: true });
const internal = await buildHostedChatGatewayContext(auth({ service: true, userId: undefined }), 'auto', 'background');
- expect(internal.plan).toBe('internal');
+ expect(internal).toMatchObject({ plan: 'internal', trial: false });
});
it('fails closed before Gateway routing when identity or plan truth is missing', async () => {