Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(desktop): default max_tokens on helper prompts (#110833)

Brandona3ba7c08196e
diff --git a/products/desktop/packages/core/src/llm-gateway/llm-gateway.test.ts b/products/desktop/packages/core/src/llm-gateway/llm-gateway.test.ts
index 88e788ecec93..0de09781ea59 100644
--- a/products/desktop/packages/core/src/llm-gateway/llm-gateway.test.ts
+++ b/products/desktop/packages/core/src/llm-gateway/llm-gateway.test.ts
@@ -568,6 +568,20 @@ describe("LlmGatewayService.prompt on the Go gateway", () => {
expect(JSON.parse(init.body).model).toBe("claude-haiku-4-5");
});
+ it("sends a default max_tokens when the caller passes none", async () => {
+ const goFetch = vi.fn().mockResolvedValue(createJsonResponse(SUCCESS_BODY));
+ const { service } = createService(vi.fn(), {
+ route: GO_ROUTE,
+ fetch: goFetch,
+ });
+
+ await service.prompt([{ role: "user", content: "hi" }], {
+ model: "claude-haiku-4-5",
+ });
+
+ expect(JSON.parse(goFetch.mock.calls[0][1].body).max_tokens).toBe(4096);
+ });
+
it("picks the free-tier model from the pin without a round trip", async () => {
const goFetch = vi.fn().mockResolvedValue(createJsonResponse(SUCCESS_BODY));
const { service } = createService(vi.fn(), {
diff --git a/products/desktop/packages/core/src/llm-gateway/llm-gateway.ts b/products/desktop/packages/core/src/llm-gateway/llm-gateway.ts
index a45be7bb8ea4..7a66eacd7cbb 100644
--- a/products/desktop/packages/core/src/llm-gateway/llm-gateway.ts
+++ b/products/desktop/packages/core/src/llm-gateway/llm-gateway.ts
@@ -40,6 +40,9 @@ export const HELPER_GATEWAY_MODEL = "claude-haiku-4-5";
const FREE_TIER_GATEWAY_MODEL = "@cf/zai-org/glm-5.2";
+// The Messages API requires max_tokens; the Go gateway forwards the body as sent.
+const HELPER_DEFAULT_MAX_TOKENS = 4096;
+
type GoRoute = Extract<GatewayRoute, { mode: "go" }>;
export function desktopUsageUrl(apiHost: string, projectId: number): string {
@@ -255,12 +258,9 @@ export class LlmGatewayService {
model,
messages: messages.map((m) => ({ role: m.role, content: m.content })),
stream: false,
+ max_tokens: maxTokens ?? HELPER_DEFAULT_MAX_TOKENS,
};
- if (maxTokens !== undefined) {
- requestBody.max_tokens = maxTokens;
- }
-
if (system) {
requestBody.system = system;
}