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(harness): keep pi's image input and model apis on the go gateway (#117133)

Brandon2409f13c1eb4
diff --git a/packages/agent/packages/harness/src/extensions/posthog-provider/models.test.ts b/packages/agent/packages/harness/src/extensions/posthog-provider/models.test.ts
index 542820f57042..ce1419c34cba 100644
--- a/packages/agent/packages/harness/src/extensions/posthog-provider/models.test.ts
+++ b/packages/agent/packages/harness/src/extensions/posthog-provider/models.test.ts
@@ -230,6 +230,63 @@ describe("resolveModelConfigs", () => {
expect(configs[0]?.api).toBe("openai-responses");
expect(configs[0]?.maxTokens).toBe(128000);
});
+
+ it.each([
+ {
+ row: {
+ id: "claude-opus-5-5",
+ owned_by: "anthropic",
+ api_shapes: ["anthropic-messages"],
+ },
+ api: "anthropic-messages",
+ input: ["text", "image"],
+ },
+ {
+ row: {
+ id: "gpt-6-sol",
+ owned_by: "openai",
+ api_shapes: ["openai-chat-completions", "openai-responses"],
+ },
+ api: "openai-responses",
+ input: ["text", "image"],
+ },
+ {
+ row: {
+ id: "zai-org/glm-5.3",
+ owned_by: "posthog",
+ api_shapes: ["openai-chat-completions", "anthropic-messages"],
+ },
+ api: "openai-completions",
+ input: ["text"],
+ },
+ {
+ row: {
+ id: "moonshotai/kimi-k3",
+ owned_by: "posthog",
+ api_shapes: ["openai-chat-completions", "anthropic-messages"],
+ },
+ api: "anthropic-messages",
+ input: ["text"],
+ },
+ {
+ row: {
+ id: "zai-org/glm-next",
+ owned_by: "posthog",
+ api_shapes: ["anthropic-messages"],
+ },
+ api: "anthropic-messages",
+ input: ["text"],
+ },
+ ])("maps the Go gateway row for $row.id", async ({ row, api, input }) => {
+ global.fetch = vi.fn().mockResolvedValue({
+ ok: true,
+ json: async () => ({ data: [row] }),
+ }) as unknown as typeof fetch;
+
+ const configs = await resolveModelConfigs("us");
+
+ expect(configs[0]).toMatchObject({ api, input });
+ });
});
describe("fallbackModelConfigs", () => {
diff --git a/packages/agent/packages/harness/src/extensions/posthog-provider/models.ts b/packages/agent/packages/harness/src/extensions/posthog-provider/models.ts
index 3f9b331638dc..a46458189886 100644
--- a/packages/agent/packages/harness/src/extensions/posthog-provider/models.ts
+++ b/packages/agent/packages/harness/src/extensions/posthog-provider/models.ts
@@ -1,7 +1,7 @@
import type { ThinkingLevelMap } from "@earendil-works/pi-ai";
import { getBuiltinModels } from "@earendil-works/pi-ai/providers/all";
import type { ProviderModelConfig } from "@earendil-works/pi-coding-agent";
-import type { CloudRegion } from "@posthog/agent-contracts";
+import { type CloudRegion, isModalModelId } from "@posthog/agent-contracts";
import { buildPosthogProjectHeaderRecord } from "@posthog/agent-contracts/posthog-property-headers";
import { getLlmGatewayUrl } from "./gateway";
@@ -23,10 +23,15 @@ export interface GatewayModel {
// Free-tier model gate: authenticated fetches mark models outside the
// caller's plan. Absence (anonymous fetch or older gateway) means allowed.
allowed?: boolean;
+ // Request formats the Go gateway accepts; absent on Python gateway rows.
+ api_shapes?: string[];
}
type ModelFamily = "anthropic" | "openai" | "cloudflare" | "baseten";
+const ANTHROPIC_MESSAGES_SHAPE = "anthropic-messages";
+const OPENAI_CHAT_COMPLETIONS_SHAPE = "openai-chat-completions";
+
const ZERO_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
// The gateway serves models before pi ships a builtin record for them. Without
@@ -68,9 +73,50 @@ function detectFamily(model: GatewayModel): ModelFamily {
if (model.owned_by === "baseten" || model.id.startsWith("deepseek-ai/")) {
return "baseten";
}
+ if (model.owned_by === "posthog") {
+ return servedModelFamily(model);
+ }
return "anthropic";
}
+// Go labels every PostHog-hosted model "posthog"; each keeps the API the
+// Python gateway's listing serves it on.
+function servedModelFamily(model: GatewayModel): ModelFamily {
+ const accepts = (shape: string) =>
+ !model.api_shapes || model.api_shapes.includes(shape);
+ const preferred = isModalModelId(model.id)
+ ? ANTHROPIC_MESSAGES_SHAPE
+ : OPENAI_CHAT_COMPLETIONS_SHAPE;
+ const other =
+ preferred === ANTHROPIC_MESSAGES_SHAPE
+ ? OPENAI_CHAT_COMPLETIONS_SHAPE
+ : ANTHROPIC_MESSAGES_SHAPE;
+ const shape = accepts(preferred) || !accepts(other) ? preferred : other;
+ return shape === ANTHROPIC_MESSAGES_SHAPE ? "anthropic" : "baseten";
+}
+
+// The Go gateway's /v1/models omits supports_vision.
+function supportsVision(
+ model: GatewayModel,
+ family: ModelFamily,
+ builtinInput: readonly string[] | undefined,
+): boolean {
+ if (model.supports_vision !== undefined) {
+ return model.supports_vision;
+ }
+ const known = FALLBACK_GATEWAY_MODELS.find((entry) => entry.id === model.id);
+ if (known?.supports_vision !== undefined) {
+ return known.supports_vision;
+ }
+ if (builtinInput) {
+ return builtinInput.includes("image");
+ }
+ return (
+ model.owned_by !== "posthog" &&
+ (family === "anthropic" || family === "openai")
+ );
+}
+
/**
* The gateway URL a model of the given pi `api` should be routed through for
* a given region. OpenAI-compatible models are served off the gateway's `/v1`
@@ -96,11 +142,14 @@ function toModelConfig(
const family = detectFamily(model);
const name = model.display_name ?? model.id;
const contextWindow = model.context_window ?? 200000;
- const input: ("text" | "image")[] = model.supports_vision
+ const builtin = findBuiltinModel(family, model.id);
+ const input: ("text" | "image")[] = supportsVision(
+ model,
+ family,
+ builtin?.input,
+ )
? ["text", "image"]
: ["text"];
-
- const builtin = findBuiltinModel(family, model.id);
const resolvedThinkingLevelMap =
THINKING_LEVEL_MAP_OVERRIDES[model.id] ?? builtin?.thinkingLevelMap;
const thinkingLevelMap = resolvedThinkingLevelMap