Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(in-app-agent): support Vertex AI for instance AI features (#17390)

Yuto Toya0dd0a7fbe2fe
diff --git a/.env.dev.example b/.env.dev.example
index a63880163a..9a2208fc7f 100644
--- a/.env.dev.example
+++ b/.env.dev.example
@@ -237,6 +237,7 @@ LANGFUSE_AI_FEATURES_PROJECT_ID=7a88fb47-b4e2-43b8-a06c-a5ce950dc53a
# LANGFUSE_AI_MODEL / LANGFUSE_AI_SMALL_MODEL / LANGFUSE_AI_AWS_BEDROCK_REGION
# apply to all providers. LANGFUSE_AI_API_KEY / LANGFUSE_AI_BASE_URL /
# LANGFUSE_AI_EXTRA_HEADERS apply to anthropic and openai.
+# LANGFUSE_AI_VERTEX_LOCATION applies to vertex.
# Langfuse AI Bedrock credentials
AWS_ACCESS_KEY_ID="A123456789"
@@ -267,6 +268,13 @@ LANGFUSE_AI_SMALL_MODEL="eu.anthropic.claude-haiku-4-5-20251001-v1:0"
# LANGFUSE_AI_BASE_URL="https://llm-exec.internal/v1"
# LANGFUSE_AI_USE_RESPONSES_API="true"
# LANGFUSE_AI_EXTRA_HEADERS='{"X-LLM-Exec-Token":"..."}'
+# Vertex AI. Authenticates through Google application default credentials, so
+# there is no key env; the GCP project is read from the same credentials.
+# Claude and Gemini model IDs are both accepted.
+# LANGFUSE_AI_PROVIDER="vertex"
+# LANGFUSE_AI_MODEL="claude-sonnet-5"
+# LANGFUSE_AI_SMALL_MODEL="gemini-3.7-flash"
+# LANGFUSE_AI_VERTEX_LOCATION="global"
LANGFUSE_IN_APP_AGENT_AWS_PROFILE="playground"
# Self-hosted Assistant instance switch. Unset or "false" hides Assistant.
# Cloud is on unless this is "false".
diff --git a/.env.prod.example b/.env.prod.example
index 70f4290a4c..6a2ebd2588 100644
--- a/.env.prod.example
+++ b/.env.prod.example
@@ -324,8 +324,9 @@ LANGFUSE_ENABLE_BLOB_STORAGE_FILE_LOG=true
# One instance-wide model for the Assistant and Ask AI, on web and worker.
# Unset LANGFUSE_AI_PROVIDER is unconfigured. Bedrock requires
-# LANGFUSE_AI_PROVIDER=bedrock. Bedrock authenticates through the AWS
-# credential chain; anthropic and openai require LANGFUSE_AI_API_KEY.
+# LANGFUSE_AI_PROVIDER=bedrock. Bedrock and vertex authenticate through their
+# cloud's default credential chain; anthropic and openai require
+# LANGFUSE_AI_API_KEY.
# LANGFUSE_AI_PROVIDER=bedrock
# LANGFUSE_AI_MODEL=eu.anthropic.claude-opus-5
# LANGFUSE_AI_SMALL_MODEL=eu.anthropic.claude-haiku-4-5-20251001-v1:0
@@ -345,6 +346,15 @@ LANGFUSE_ENABLE_BLOB_STORAGE_FILE_LOG=true
# LANGFUSE_AI_USE_RESPONSES_API=true
# LANGFUSE_AI_EXTRA_HEADERS={"X-LLM-Exec-Token":"..."}
+# Vertex AI authenticates through Google application default credentials, so a
+# Cloud Run or GKE workload needs no key env. The GCP project is read from the
+# same credentials. Claude and Gemini model IDs are both accepted.
+# LANGFUSE_AI_PROVIDER=vertex
+# LANGFUSE_AI_MODEL=claude-sonnet-5
+# LANGFUSE_AI_SMALL_MODEL=gemini-3.7-flash
+# Optional, defaults to global
+# LANGFUSE_AI_VERTEX_LOCATION=global
+
# Workers follow LANGFUSE_IN_APP_AGENT_ENABLED for the run queue and integrity
# runner. Split-role workers (ingestion-only) can opt out without turning the
# instance off:
diff --git a/docker-compose.build.yml b/docker-compose.build.yml
index 3a0120001a..b493732010 100644
--- a/docker-compose.build.yml
+++ b/docker-compose.build.yml
@@ -67,6 +67,7 @@ services:
LANGFUSE_AI_USE_RESPONSES_API: ${LANGFUSE_AI_USE_RESPONSES_API:-}
LANGFUSE_AI_EXTRA_HEADERS: ${LANGFUSE_AI_EXTRA_HEADERS:-}
LANGFUSE_AI_AWS_BEDROCK_REGION: ${LANGFUSE_AI_AWS_BEDROCK_REGION:-}
+ LANGFUSE_AI_VERTEX_LOCATION: ${LANGFUSE_AI_VERTEX_LOCATION:-}
LANGFUSE_IN_APP_AGENT_ENABLED: ${LANGFUSE_IN_APP_AGENT_ENABLED:-}
LANGFUSE_EVALUATOR_MEDIA_TRANSPORT: ${LANGFUSE_EVALUATOR_MEDIA_TRANSPORT:-}
LANGFUSE_EVALUATOR_MEDIA_INLINE_MAX_BYTES: ${LANGFUSE_EVALUATOR_MEDIA_INLINE_MAX_BYTES:-}
diff --git a/docker-compose.yml b/docker-compose.yml
index 52fd3952a4..40293a8f54 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -92,6 +92,7 @@ services:
LANGFUSE_AI_USE_RESPONSES_API: ${LANGFUSE_AI_USE_RESPONSES_API:-}
LANGFUSE_AI_EXTRA_HEADERS: ${LANGFUSE_AI_EXTRA_HEADERS:-}
LANGFUSE_AI_AWS_BEDROCK_REGION: ${LANGFUSE_AI_AWS_BEDROCK_REGION:-}
+ LANGFUSE_AI_VERTEX_LOCATION: ${LANGFUSE_AI_VERTEX_LOCATION:-}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-}
AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN:-}
diff --git a/packages/shared/src/env.ts b/packages/shared/src/env.ts
index 430a75130d..13f52ae40b 100644
--- a/packages/shared/src/env.ts
+++ b/packages/shared/src/env.ts
@@ -534,7 +534,12 @@ const EnvSchema = z.object({
// apply to all providers. LANGFUSE_AI_API_KEY / LANGFUSE_AI_BASE_URL /
// LANGFUSE_AI_EXTRA_HEADERS apply to anthropic and openai.
// LANGFUSE_AI_USE_RESPONSES_API applies to openai only.
- LANGFUSE_AI_PROVIDER: z.enum(["bedrock", "anthropic", "openai"]).optional(),
+ // LANGFUSE_AI_VERTEX_LOCATION applies to vertex only; like bedrock, vertex
+ // authenticates through the instance credential chain (GCP application
+ // default credentials) and takes no key.
+ LANGFUSE_AI_PROVIDER: z
+ .enum(["bedrock", "anthropic", "openai", "vertex"])
+ .optional(),
LANGFUSE_AI_MODEL: z.string().optional(),
LANGFUSE_AI_SMALL_MODEL: z.string().optional(),
LANGFUSE_AI_API_KEY: z.string().optional(),
@@ -562,6 +567,7 @@ const EnvSchema = z.object({
},
),
LANGFUSE_AI_AWS_BEDROCK_REGION: z.string().optional(),
+ LANGFUSE_AI_VERTEX_LOCATION: z.string().optional(),
LANGFUSE_IN_APP_AGENT_ENABLED: z.enum(["true", "false"]).optional(),
LANGFUSE_EVALUATOR_MEDIA_TRANSPORT: z
.enum(["url", "inline", "disabled"])
diff --git a/packages/shared/src/in-app-agent/server/modelProvider.test.ts b/packages/shared/src/in-app-agent/server/modelProvider.test.ts
index 112ad34f56..2c2f481d82 100644
--- a/packages/shared/src/in-app-agent/server/modelProvider.test.ts
+++ b/packages/shared/src/in-app-agent/server/modelProvider.test.ts
@@ -16,6 +16,7 @@ const original = {
LANGFUSE_AI_USE_RESPONSES_API: env.LANGFUSE_AI_USE_RESPONSES_API,
LANGFUSE_AI_EXTRA_HEADERS: env.LANGFUSE_AI_EXTRA_HEADERS,
LANGFUSE_AI_AWS_BEDROCK_REGION: env.LANGFUSE_AI_AWS_BEDROCK_REGION,
+ LANGFUSE_AI_VERTEX_LOCATION: env.LANGFUSE_AI_VERTEX_LOCATION,
LANGFUSE_IN_APP_AGENT_ENABLED: env.LANGFUSE_IN_APP_AGENT_ENABLED,
NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION,
};
@@ -206,6 +207,92 @@ describe("getInAppAgentModelConfig", () => {
expect(getInAppAgentModelConfig()).toBeUndefined();
});
+ it("resolves Vertex from LANGFUSE_AI_PROVIDER and LANGFUSE_AI_VERTEX_LOCATION", () => {
+ Object.assign(env, {
+ LANGFUSE_AI_PROVIDER: "vertex",
+ LANGFUSE_AI_MODEL: "claude-sonnet-4-5@20250929",
+ LANGFUSE_AI_SMALL_MODEL: "gemini-2.5-flash",
+ LANGFUSE_AI_API_KEY: undefined,
+ LANGFUSE_AI_BASE_URL: undefined,
+ LANGFUSE_AI_EXTRA_HEADERS: undefined,
+ LANGFUSE_AI_USE_RESPONSES_API: undefined,
+ LANGFUSE_AI_VERTEX_LOCATION: "us-east5",
+ NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: undefined,
+ });
+
+ expect(getInAppAgentModelConfig()).toEqual({
+ provider: "vertex",
+ modelId: "claude-sonnet-4-5@20250929",
+ titleModelId: "gemini-2.5-flash",
+ location: "us-east5",
+ });
+ });
+
+ it("leaves the Vertex location undefined when LANGFUSE_AI_VERTEX_LOCATION is unset", () => {
+ Object.assign(env, {
+ LANGFUSE_AI_PROVIDER: "vertex",
+ LANGFUSE_AI_MODEL: "gemini-2.5-pro",
+ LANGFUSE_AI_SMALL_MODEL: undefined,
+ LANGFUSE_AI_API_KEY: undefined,
+ LANGFUSE_AI_BASE_URL: undefined,
+ LANGFUSE_AI_EXTRA_HEADERS: undefined,
+ LANGFUSE_AI_USE_RESPONSES_API: undefined,
+ LANGFUSE_AI_VERTEX_LOCATION: undefined,
+ NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: undefined,
+ });
+
+ expect(getInAppAgentModelConfig()).toEqual({
+ provider: "vertex",
+ modelId: "gemini-2.5-pro",
+ titleModelId: "gemini-2.5-pro",
+ location: undefined,
+ });
+ });
+
+ it("treats an invalid LANGFUSE_AI_VERTEX_LOCATION as unconfigured", () => {
+ Object.assign(env, {
+ LANGFUSE_AI_PROVIDER: "vertex",
+ LANGFUSE_AI_MODEL: "gemini-2.5-pro",
+ LANGFUSE_AI_SMALL_MODEL: undefined,
+ LANGFUSE_AI_API_KEY: undefined,
+ LANGFUSE_AI_BASE_URL: undefined,
+ LANGFUSE_AI_EXTRA_HEADERS: undefined,
+ LANGFUSE_AI_USE_RESPONSES_API: undefined,
+ LANGFUSE_AI_VERTEX_LOCATION: "us-east5.attacker.test",
+ NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: undefined,
+ });
+
+ expect(getInAppAgentModelConfig()).toBeUndefined();
+ });
+
+ it("warns that key-bearing variables are ignored on Vertex", () => {
+ const warn = vi.spyOn(logger, "warn").mockImplementation(() => logger);
+
+ Object.assign(env, {
+ LANGFUSE_AI_PROVIDER: "vertex",
+ LANGFUSE_AI_MODEL: "gemini-2.5-pro",
+ LANGFUSE_AI_SMALL_MODEL: undefined,
+ LANGFUSE_AI_API_KEY: "sk-test",
+ LANGFUSE_AI_BASE_URL: "https://api.anthropic.com",
+ LANGFUSE_AI_EXTRA_HEADERS: undefined,
+ LANGFUSE_AI_USE_RESPONSES_API: undefined,
+ LANGFUSE_AI_VERTEX_LOCATION: "global",
+ NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: undefined,
+ });
+
+ expect(getInAppAgentModelConfig()).toEqual({
+ provider: "vertex",
+ modelId: "gemini-2.5-pro",
+ titleModelId: "gemini-2.5-pro",
+ location: "global",
+ });
+ expect(warn).toHaveBeenCalledTimes(1);
+ expect(warn.mock.calls[0]?.[0]).toEqual(
+ "Ignoring LANGFUSE_AI_API_KEY and LANGFUSE_AI_BASE_URL because the Langfuse AI provider is vertex. Vertex AI uses GCP application default credentials, not an API key, base URL, extra headers, or the OpenAI Responses API toggle.",
+ );
+
+ warn.mockRestore();
+ });
});
describe("isInAppAgentInstanceEnabled", () => {
diff --git a/packages/shared/src/in-app-agent/server/modelProvider.ts b/packages/shared/src/in-app-agent/server/modelProvider.ts
index a21746c490..f4f72b57ff 100644
--- a/packages/shared/src/in-app-agent/server/modelProvider.ts
+++ b/packages/shared/src/in-app-agent/server/modelProvider.ts
@@ -7,9 +7,13 @@ import {
getLangfuseAIBedrockRegion,
} from "../../server/llm/ai-sdk/providers/bedrock";
import { toAnthropicBaseURL } from "../../server/llm/ai-sdk/providers/anthropic";
+import {
+ assertValidVertexLocation,
+ getLangfuseAIVertexLocation,
+} from "../../server/llm/ai-sdk/providers/vertex";
import { processOpenAIBaseURL } from "../../server/llm/utils";
-export type LangfuseAIProvider = "bedrock" | "anthropic" | "openai";
+export type LangfuseAIProvider = "bedrock" | "anthropic" | "openai" | "vertex";
type LangfuseAIHttpProviderConfig = {
modelId: string;
@@ -31,7 +35,13 @@ export type InAppAgentModelConfig =
} & LangfuseAIHttpProviderConfig)
| ({
provider: "openai";
- } & LangfuseAIHttpProviderConfig);
+ } & LangfuseAIHttpProviderConfig)
+ | {
+ provider: "vertex";
+ modelId: string;
+ titleModelId: string;
+ location?: string;
+ };
export const LANGFUSE_AI_MODEL_UNCONFIGURED_MESSAGE =
"Langfuse AI is not configured. Set LANGFUSE_AI_PROVIDER and LANGFUSE_AI_MODEL, plus LANGFUSE_AI_API_KEY when LANGFUSE_AI_PROVIDER is anthropic or openai.";
@@ -42,18 +52,23 @@ const extraHeadersRecordSchema = z.record(z.string(), z.string());
* Resolves the instance-wide Langfuse-operated AI model (Assistant + Ask AI).
*
* Callers should not branch on vendor beyond this discriminated config.
- * `LANGFUSE_AI_PROVIDER` selects `bedrock`, `anthropic`, or `openai`. Unset
- * provider is unconfigured, even when model variables and
+ * `LANGFUSE_AI_PROVIDER` selects `bedrock`, `anthropic`, `openai`, or
+ * `vertex`. Unset provider is unconfigured, even when model variables and
* `NEXT_PUBLIC_LANGFUSE_CLOUD_REGION` are set. Bedrock requires
* `LANGFUSE_AI_PROVIDER=bedrock`.
*
- * Region is optional for Bedrock: Cloud web historically omits it and lets
- * the AWS SDK use the task region.
+ * Bedrock and Vertex authenticate through the instance credential chain (the
+ * AWS default chain / GCP application default credentials) and read no key.
+ *
+ * Region and location are optional: Cloud web historically omits the Bedrock
+ * region and lets the AWS SDK use the task region, and an unset Vertex
+ * location falls back to the "global" endpoint.
*
* LANGFUSE_AI_MODEL / LANGFUSE_AI_SMALL_MODEL / LANGFUSE_AI_AWS_BEDROCK_REGION
* apply to all providers. LANGFUSE_AI_API_KEY / LANGFUSE_AI_BASE_URL /
* LANGFUSE_AI_EXTRA_HEADERS apply to anthropic and openai.
* LANGFUSE_AI_USE_RESPONSES_API applies to openai only.
+ * LANGFUSE_AI_VERTEX_LOCATION applies to vertex only.
*/
export function getInAppAgentModelConfig(params?: {
modelId?: string | null;
@@ -68,19 +83,39 @@ export function getInAppAgentModelConfig(params?: {
}
const modelId = params?.modelId ?? env.LANGFUSE_AI_MODEL;
- const region = getLangfuseAIBedrockRegion();
if (!modelId) {
return undefined;
}
+ if (provider === "vertex") {
+ const location = getLangfuseAIVertexLocation();
+
+ try {
+ assertValidVertexLocation(location);
+ } catch {
+ return undefined;
+ }
+
+ warnIfInstanceCredentialsIgnoreKeyEnv("vertex");
+
+ return {
+ provider: "vertex",
+ modelId,
+ titleModelId: env.LANGFUSE_AI_SMALL_MODEL ?? modelId,
+ location,
+ };
+ }
+
+ const region = getLangfuseAIBedrockRegion();
+
try {
assertValidBedrockRegion(region);
} catch {
return undefined;
}
- warnIfBedrockIgnoresNonBedrockEnv();
+ warnIfInstanceCredentialsIgnoreKeyEnv("bedrock");
return {
provider: "bedrock",
@@ -139,7 +174,11 @@ function parseLangfuseAIExtraHeaders(): Record<string, string> | undefined {
return Object.keys(headers).length > 0 ? headers : undefined;
}
-function warnIfBedrockIgnoresNonBedrockEnv() {
+/**
+ * Bedrock and Vertex authenticate through the instance credential chain, so the
+ * key-bearing environment variables silently do nothing under them.
+ */
+function warnIfInstanceCredentialsIgnoreKeyEnv(provider: "bedrock" | "vertex") {
const ignored: string[] = [];
if (env.LANGFUSE_AI_API_KEY) {
ignored.push("LANGFUSE_AI_API_KEY");
@@ -157,8 +196,19 @@ function warnIfBedrockIgnoresNonBedrockEnv() {
return;
}
+ const { label, credentialChain } =
+ provider === "bedrock"
+ ? {
+ label: "Bedrock",
+ credentialChain: "the instance AWS credential chain",
+ }
+ : {
+ label: "Vertex AI",
+ credentialChain: "GCP application default credentials",
+ };
+
logger.warn(
- `Ignoring ${ignored.join(" and ")} because the Langfuse AI provider is bedrock. Bedrock uses the instance AWS credential chain, not an API key, base URL, extra headers, or the OpenAI Responses API toggle.`,
+ `Ignoring ${ignored.join(" and ")} because the Langfuse AI provider is ${provider}. ${label} uses ${credentialChain}, not an API key, base URL, extra headers, or the OpenAI Responses API toggle.`,
);
}
diff --git a/packages/shared/src/server/index.ts b/packages/shared/src/server/index.ts
index 80a8849e89..bea12ab5a9 100644
--- a/packages/shared/src/server/index.ts
+++ b/packages/shared/src/server/index.ts
@@ -61,6 +61,8 @@ export * from "./llm/compileChatMessages";
export * from "./llm/testModelCall";
export * from "./llm/baseUrlValidation";
export * from "./llm/ai-sdk/providers/bedrock";
+export * from "./llm/ai-sdk/providers/vertex";
+export * from "./llm/ai-sdk/providers/vertexAuth";
export * from "./outbound-url";
export * from "./services/blobStorageEndpointValidation";
export * from "./llm/getInternalTracingHandler";
diff --git a/packages/shared/src/server/llm/ai-sdk/providers/index.ts b/packages/shared/src/server/llm/ai-sdk/providers/index.ts
index cdc9a0f4f6..498308c39c 100644
--- a/packages/shared/src/server/llm/ai-sdk/providers/index.ts
+++ b/packages/shared/src/server/llm/ai-sdk/providers/index.ts
@@ -109,6 +109,7 @@ export async function buildAiSdkModel(params: {
apiKey,
config,
extraHeaders,
+ credentialSource,
fetch: createFetch(
isClaudeModel(model.id)
? "Anthropic Vertex AI endpoint"
diff --git a/packages/shared/src/server/llm/ai-sdk/providers/vertex.ts b/packages/shared/src/server/llm/ai-sdk/providers/vertex.ts
index 27133b78fb..363b4453d6 100644
--- a/packages/shared/src/server/llm/ai-sdk/providers/vertex.ts
+++ b/packages/shared/src/server/llm/ai-sdk/providers/vertex.ts
@@ -1,7 +1,7 @@
import { createVertex } from "@ai-sdk/google-vertex";
import { createVertexAnthropic } from "@ai-sdk/google-vertex/anthropic";
import type { LanguageModel } from "ai";
-import { GoogleAuth, type GoogleAuthOptions } from "google-auth-library";
+import { type GoogleAuthOptions } from "google-auth-library";
import { env } from "../../../../env";
import {
@@ -10,10 +10,8 @@ import {
VERTEXAI_USE_DEFAULT_CREDENTIALS,
VertexAIConfigSchema,
} from "../../../../interfaces/customLLMProviderConfigSchemas";
-
-const VERTEX_AI_AUTH_SCOPES = [
- "https://www.googleapis.com/auth/cloud-platform",
-];
+import type { LLMCredentialSource } from "./types";
+import { resolveVertexProjectIdFromADC } from "./vertexAuth";
const ANTHROPIC_VERTEX_MODEL_NAME_PATTERN = /^[A-Za-z0-9_.@-]+$/;
@@ -49,32 +47,48 @@ export function assertValidVertexLocation(location: string | undefined): void {
}
}
+/**
+ * Vertex location for Langfuse-operated AI (Assistant, Ask AI). Undefined
+ * falls back to the same "global" endpoint existing connections default to.
+ */
+export function getLangfuseAIVertexLocation(): string | undefined {
+ return env.LANGFUSE_AI_VERTEX_LOCATION;
+}
+
/**
* Builds a Vertex AI model: Gemini via `@ai-sdk/google-vertex`, Claude via its
* `/anthropic` entry point (Anthropic Messages over Vertex `rawPredict`).
*
* The decrypted secret is either a GCP service account key (project taken from
* the key; user-supplied project IDs are never honored) or the ADC sentinel,
- * allowed only in self-hosted deployments, in which case the project is
- * resolved from the default credential chain.
+ * allowed for self-hosted deployments and for Langfuse-operated AI, in which
+ * case the project is resolved from the default credential chain.
*/
export async function buildVertexModel(params: {
modelId: string;
apiKey: string;
config?: LLMConnectionConfig | null;
extraHeaders?: Record<string, string>;
+ credentialSource: LLMCredentialSource;
fetch: typeof fetch;
}): Promise<LanguageModel> {
- const { modelId, apiKey, config, extraHeaders } = params;
-
- const { location } = config
- ? VertexAIConfigSchema.parse(config)
- : { location: undefined };
+ const { modelId, apiKey, config, extraHeaders, credentialSource } = params;
+ const shouldUseLangfuseAPIKey = credentialSource === "langfuse";
+
+ // Langfuse-operated AI carries no persisted connection, so its location comes
+ // from the instance env instead of the connection config.
+ let location: string | undefined;
+ if (shouldUseLangfuseAPIKey) {
+ location = getLangfuseAIVertexLocation();
+ } else if (config) {
+ location = VertexAIConfigSchema.parse(config).location;
+ }
assertValidVertexLocation(location);
const isLangfuseCloud = Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);
const shouldUseDefaultCredentials =
- apiKey === VERTEXAI_USE_DEFAULT_CREDENTIALS && !isLangfuseCloud;
+ apiKey === VERTEXAI_USE_DEFAULT_CREDENTIALS &&
+ (!isLangfuseCloud || shouldUseLangfuseAPIKey);
// Security: with ADC we intentionally ignore user-provided project IDs to
// prevent privilege escalation via the server's credentials.
@@ -91,8 +105,7 @@ export async function buildVertexModel(params: {
// The AI SDK requires an explicit project for URL construction (it does not
// ask the auth library); resolve it from ADC when no key is configured.
const project =
- serviceAccountKey?.project_id ??
- (await new GoogleAuth({ scopes: VERTEX_AI_AUTH_SCOPES }).getProjectId());
+ serviceAccountKey?.project_id ?? (await resolveVertexProjectIdFromADC());
// Existing connections default the location to "global" for both families.
const resolvedLocation = location ?? "global";
diff --git a/packages/shared/src/server/llm/ai-sdk/providers/vertexAuth.ts b/packages/shared/src/server/llm/ai-sdk/providers/vertexAuth.ts
new file mode 100644
index 0000000000..dfc354f863
--- /dev/null
+++ b/packages/shared/src/server/llm/ai-sdk/providers/vertexAuth.ts
@@ -0,0 +1,63 @@
+import { GoogleAuth } from "google-auth-library";
+
+const VERTEX_AI_AUTH_SCOPES = [
+ "https://www.googleapis.com/auth/cloud-platform",
+];
+
+let googleAuth: GoogleAuth | undefined;
+let projectIdPromise: Promise<string> | undefined;
+
+function getVertexGoogleAuth(): GoogleAuth {
+ if (!googleAuth) {
+ googleAuth = new GoogleAuth({ scopes: VERTEX_AI_AUTH_SCOPES });
+ }
+ return googleAuth;
+}
+
+/**
+ * GCP project for Vertex requests that authenticate through application
+ * default credentials.
+ *
+ * The AI SDK requires an explicit project for URL construction (it does not ask
+ * the auth library), so callers that have no service account key resolve it
+ * here instead.
+ *
+ * The answer is a property of the deployment's own credentials and cannot
+ * change while the process runs, so it is resolved once. Without that, every
+ * model build repeats the lookup, which falls through to the GCE metadata
+ * server on Cloud Run and GKE — a round trip on each Assistant run, Ask AI
+ * request and search-bar query. A rejection is not kept, so a transient
+ * metadata failure does not poison the process.
+ *
+ * This lives apart from `vertex.ts` so the worker can reach it without a direct
+ * dependency on google-auth-library, which pnpm's strict layout does not expose
+ * to that package. Pass `generateVertexAccessTokenFromADC` into the Vertex
+ * Anthropic factory for the same reason: otherwise the worker's nested SDK
+ * copy constructs GoogleAuth itself.
+ */
+export async function resolveVertexProjectIdFromADC(): Promise<string> {
+ if (!projectIdPromise) {
+ projectIdPromise = getVertexGoogleAuth()
+ .getProjectId()
+ .catch((error: unknown) => {
+ projectIdPromise = undefined;
+ throw error;
+ });
+ }
+
+ return projectIdPromise;
+}
+
+/**
+ * OAuth access token from the same ADC chain as
+ * `resolveVertexProjectIdFromADC`.
+ *
+ * Tokens expire, so they are fetched per call. The GoogleAuth client is reused.
+ */
+export async function generateVertexAccessTokenFromADC(): Promise<
+ string | null
+> {
+ const client = await getVertexGoogleAuth().getClient();
+ const token = await client.getAccessToken();
+ return token?.token ?? null;
+}
diff --git a/packages/shared/src/server/llm/ai-sdk/requestShape.test.ts b/packages/shared/src/server/llm/ai-sdk/requestShape.test.ts
index f950dc5ef2..3b41d80451 100644
--- a/packages/shared/src/server/llm/ai-sdk/requestShape.test.ts
+++ b/packages/shared/src/server/llm/ai-sdk/requestShape.test.ts
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { encrypt } from "../../../encryption";
import { env } from "../../../env";
+import { VERTEXAI_USE_DEFAULT_CREDENTIALS } from "../../../interfaces/customLLMProviderConfigSchemas";
import {
type ChatMessage,
ChatMessageRole,
@@ -663,6 +664,90 @@ describe("AI SDK request shapes", () => {
expect(request.body.max_tokens).toBe(128);
});
+ // Vertex reaches application default credentials through two independent
+ // gates: the ADC sentinel in place of a key, and a credential source that is
+ // allowed to spend the server's own identity. The pair below pins both
+ // directions of that gate, because widening it hands a tenant connection the
+ // Langfuse deployment's GCP identity and narrowing it silently disables
+ // instance-wide Vertex wherever the Cloud region is set.
+ it("Langfuse AI Vertex resolves the project from ADC, Cloud region notwithstanding", async () => {
+ const original = {
+ LANGFUSE_AI_PROVIDER: env.LANGFUSE_AI_PROVIDER,
+ LANGFUSE_AI_MODEL: env.LANGFUSE_AI_MODEL,
+ LANGFUSE_AI_SMALL_MODEL: env.LANGFUSE_AI_SMALL_MODEL,
+ LANGFUSE_AI_VERTEX_LOCATION: env.LANGFUSE_AI_VERTEX_LOCATION,
+ NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION,
+ };
+ Object.assign(env, {
+ LANGFUSE_AI_PROVIDER: "vertex",
+ LANGFUSE_AI_MODEL: "claude-sonnet-4-5@20250929",
+ LANGFUSE_AI_SMALL_MODEL: undefined,
+ LANGFUSE_AI_VERTEX_LOCATION: "us-east5",
+ NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: "eu",
+ });
+
+ try {
+ const { calls, fetch } = createCaptureFetch(ANTHROPIC_RESPONSE);
+ vi.stubGlobal("fetch", fetch);
+
+ const text = await generateLangfuseAIText({
+ messages,
+ maxTokens: 128,
+ timeout: 10_000,
+ });
+
+ expect(text).toBe("ok");
+ expect(calls).toHaveLength(1);
+ // The project comes from the credential chain, never from configuration,
+ // and the location comes from the instance env rather than a connection.
+ expect(decodeURIComponent(calls[0]?.url ?? "")).toBe(
+ "https://us-east5-aiplatform.googleapis.com/v1/projects/adc-project/locations/us-east5/publishers/anthropic/models/claude-sonnet-4-5@20250929:rawPredict",
+ );
+ expect(calls[0]?.headers.get("authorization")).toBe(
+ "Bearer fake-gcp-token",
+ );
+ } finally {
+ Object.assign(env, original);
+ }
+ });
+
+ it("a tenant Vertex connection cannot spend ADC on Langfuse Cloud", async () => {
+ const original = {
+ NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION,
+ };
+ Object.assign(env, { NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: "eu" });
+
+ try {
+ const { calls, fetch } = createCaptureFetch(GOOGLE_RESPONSE);
+ vi.stubGlobal("fetch", fetch);
+
+ await expect(
+ generateLLMText({
+ ...mapLegacyLLMCompletionParams({
+ messages,
+ modelParams: {
+ provider: "vertex",
+ adapter: LLMAdapter.VertexAI,
+ model: "gemini-2.5-flash",
+ },
+ connection: {
+ secretKey: encrypt(VERTEXAI_USE_DEFAULT_CREDENTIALS),
+ config: { location: "us-east5" },
+ },
+ credentialSource: "user",
+ }),
+ timeout: 10_000,
+ }),
+ ).rejects.toThrow();
+
+ // The sentinel must not fall back to the server's identity: no request
+ // may leave carrying the deployment's ADC project.
+ expect(calls).toHaveLength(0);
+ } finally {
+ Object.assign(env, original);
+ }
+ });
+
// The Bedrock builder deliberately uses no custom fetch (VPC endpoints),
// so capture at the global fetch the AI SDK falls back to.
async function runBedrockCompletion(params?: {
diff --git a/packages/shared/src/server/llm/ai-sdk/resolveAiSdkModelConfig.ts b/packages/shared/src/server/llm/ai-sdk/resolveAiSdkModelConfig.ts
index 6a03baaa76..f52081812b 100644
--- a/packages/shared/src/server/llm/ai-sdk/resolveAiSdkModelConfig.ts
+++ b/packages/shared/src/server/llm/ai-sdk/resolveAiSdkModelConfig.ts
@@ -41,12 +41,13 @@ export function resolveAiSdkModelConfig(params: {
credentialSource === "langfuse" &&
model.adapter !== LLMAdapter.Bedrock &&
model.adapter !== LLMAdapter.Anthropic &&
- model.adapter !== LLMAdapter.OpenAI
+ model.adapter !== LLMAdapter.OpenAI &&
+ model.adapter !== LLMAdapter.VertexAI
) {
throw new LLMValidationError({
code: "invalid-connection",
message:
- "Langfuse credentials are only supported for Amazon Bedrock, Anthropic, and OpenAI",
+ "Langfuse credentials are only supported for Amazon Bedrock, Anthropic, OpenAI, and Vertex AI",
});
}
diff --git a/packages/shared/src/server/llm/langfuseAiCompletion.ts b/packages/shared/src/server/llm/langfuseAiCompletion.ts
index 181105caed..509b8fb6af 100644
--- a/packages/shared/src/server/llm/langfuseAiCompletion.ts
+++ b/packages/shared/src/server/llm/langfuseAiCompletion.ts
@@ -1,4 +1,7 @@
-import { BEDROCK_USE_DEFAULT_CREDENTIALS } from "../../interfaces/customLLMProviderConfigSchemas";
+import {
+ BEDROCK_USE_DEFAULT_CREDENTIALS,
+ VERTEXAI_USE_DEFAULT_CREDENTIALS,
+} from "../../interfaces/customLLMProviderConfigSchemas";
import { encrypt } from "../../encryption";
import { env } from "../../env";
import {
@@ -140,6 +143,24 @@ function toLangfuseAICompletionParams(params: {
},
credentialSource: "langfuse" as const,
};
+ case "vertex":
+ return {
+ messages,
+ modelParams: {
+ provider: "vertex",
+ adapter: LLMAdapter.VertexAI,
+ model: modelConfig.modelId,
+ // Same reasoning as Bedrock: newer Vertex models reject these
+ // inference params.
+ ...maxTokens,
+ },
+ // No config travels with the connection: the location rides the
+ // instance env, mirroring how Bedrock resolves its region.
+ connection: {
+ secretKey: encrypt(VERTEXAI_USE_DEFAULT_CREDENTIALS),
+ },
+ credentialSource: "langfuse" as const,
+ };
default: {
const _exhaustive: never = modelConfig;
throw new Error(
diff --git a/packages/shared/src/server/llm/llmText.test.ts b/packages/shared/src/server/llm/llmText.test.ts
index d2cdcc681c..664e76a027 100644
--- a/packages/shared/src/server/llm/llmText.test.ts
+++ b/packages/shared/src/server/llm/llmText.test.ts
@@ -633,7 +633,7 @@ describe("legacy compatibility boundary", () => {
).rejects.toMatchObject({
name: "LLMValidationError",
message:
- "Langfuse credentials are only supported for Amazon Bedrock, Anthropic, and OpenAI",
+ "Langfuse credentials are only supported for Amazon Bedrock, Anthropic, OpenAI, and Vertex AI",
statusCode: 400,
code: "invalid-connection",
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 1be0665752..41786349dc 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1147,6 +1147,9 @@ importers:
ai-sdk-anthropic-v4:
specifier: npm:@ai-sdk/[email protected]
+ ai-sdk-google-vertex-v4:
+ specifier: npm:@ai-sdk/[email protected]
ai-sdk-openai-compatible-v4:
specifier: npm:@ai-sdk/[email protected]
@@ -1361,18 +1364,36 @@ packages:
peerDependencies:
zod: 4.3.6
+ '@ai-sdk/[email protected]':
+ resolution: {integrity: sha512-bqO5JwWtAlVeSL2R4tGm+qpqzjP/szns5MWpeESkJ8Ub8FwBchu2WynYhNih6hFDcau9n+BMtq72NJ2uZfs2Ew==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ zod: 4.3.6
+
'@ai-sdk/[email protected]':
resolution: {integrity: sha512-WRu4srlMC5l2DygS1q6Tb8Dqgcwwrdu9Lb/u+0LaLMJZK/zzfhO3bGpGpNxiIsv+k9GYQxvAc3o9NpPcgX9I5g==}
engines: {node: '>=22'}
peerDependencies:
zod: 4.3.6
+ '@ai-sdk/[email protected]':
+ resolution: {integrity: sha512-XWWju5pVD7Tf30c2VziMfPph3XpN/jDTE5aJhqAPJ2zRmHSSveNYFoosFLOWWFIgQnwGe9AM3bAXR8kHyC2MdA==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ zod: 4.3.6
+
'@ai-sdk/[email protected]':
resolution: {integrity: sha512-YJnWlHVqG6Lq3NY5Z0hs1+8+P4GFTBLPkmnuFIGdsYi19qB7C36IpK2JOzdkyE47waVJuu6tq/d0rFyHZzY2MQ==}
engines: {node: '>=22'}
peerDependencies:
zod: 4.3.6
+ '@ai-sdk/[email protected]':
+ resolution: {integrity: sha512-2OUf83ezu8UmyN9knPo2AgJ+CoJronxvULgSUdA1GgTU0Codku7XnHjwKHppk9FPLDW0eg+Y4V6iOKWMTlqEzA==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ zod: 4.3.6
+
'@ai-sdk/[email protected]':
resolution: {integrity: sha512-+mDaUS0q460pVs3oW2/Ps/vj4M2EZnYr1v6ng8TmzxnZPrYBuK7PGQIfckqFdWIdUI/gG8BXcaf8vukLKyGU6Q==}
engines: {node: '>=22'}
@@ -12828,6 +12849,18 @@ snapshots:
'@vercel/oidc': 3.2.0
zod: 4.3.6
+ dependencies:
+ '@ai-sdk/anthropic': 3.0.111([email protected])
+ '@ai-sdk/google': 3.0.111([email protected])
+ '@ai-sdk/openai-compatible': 2.0.70([email protected])
+ '@ai-sdk/provider': 3.0.15
+ '@ai-sdk/provider-utils': 4.0.46([email protected])
+ google-auth-library: 10.6.2([email protected])
+ zod: 4.3.6
+ transitivePeerDependencies:
+ - supports-color
+
dependencies:
'@ai-sdk/anthropic': 4.0.5([email protected])
@@ -12840,12 +12873,24 @@ snapshots:
transitivePeerDependencies:
- supports-color
+ dependencies:
+ '@ai-sdk/provider': 3.0.15
+ '@ai-sdk/provider-utils': 4.0.46([email protected])
+ zod: 4.3.6
+
dependencies:
'@ai-sdk/provider': 4.0.1
'@ai-sdk/provider-utils': 5.0.3([email protected])
zod: 4.3.6
+ dependencies:
+ '@ai-sdk/provider': 3.0.15
+ '@ai-sdk/provider-utils': 4.0.46([email protected])
+ zod: 4.3.6
+
dependencies:
'@ai-sdk/provider': 4.0.1
diff --git a/web/src/env.mjs b/web/src/env.mjs
index 2366b55133..eb297bcbbe 100644
--- a/web/src/env.mjs
+++ b/web/src/env.mjs
@@ -530,7 +530,12 @@ export const env = createEnv({
// apply to all providers. LANGFUSE_AI_API_KEY / LANGFUSE_AI_BASE_URL /
// LANGFUSE_AI_EXTRA_HEADERS apply to anthropic and openai.
// LANGFUSE_AI_USE_RESPONSES_API applies to openai only.
- LANGFUSE_AI_PROVIDER: z.enum(["bedrock", "anthropic", "openai"]).optional(),
+ // LANGFUSE_AI_VERTEX_LOCATION applies to vertex only; like bedrock, vertex
+ // authenticates through the instance credential chain (GCP application
+ // default credentials) and takes no key.
+ LANGFUSE_AI_PROVIDER: z
+ .enum(["bedrock", "anthropic", "openai", "vertex"])
+ .optional(),
LANGFUSE_AI_MODEL: z.string().optional(),
LANGFUSE_AI_SMALL_MODEL: z.string().optional(),
LANGFUSE_AI_API_KEY: z.string().optional(),
@@ -558,6 +563,7 @@ export const env = createEnv({
},
),
LANGFUSE_AI_AWS_BEDROCK_REGION: z.string().optional(),
+ LANGFUSE_AI_VERTEX_LOCATION: z.string().optional(),
LANGFUSE_IN_APP_AGENT_ENABLED: z.enum(["true", "false"]).optional(),
LANGFUSE_EVALUATOR_MEDIA_TRANSPORT: z
.enum(["url", "inline", "disabled"])
@@ -1163,6 +1169,7 @@ export const env = createEnv({
LANGFUSE_AI_USE_RESPONSES_API: process.env.LANGFUSE_AI_USE_RESPONSES_API,
LANGFUSE_AI_EXTRA_HEADERS: process.env.LANGFUSE_AI_EXTRA_HEADERS,
LANGFUSE_AI_AWS_BEDROCK_REGION: process.env.LANGFUSE_AI_AWS_BEDROCK_REGION,
+ LANGFUSE_AI_VERTEX_LOCATION: process.env.LANGFUSE_AI_VERTEX_LOCATION,
LANGFUSE_IN_APP_AGENT_ENABLED: process.env.LANGFUSE_IN_APP_AGENT_ENABLED,
LANGFUSE_EVALUATOR_MEDIA_TRANSPORT:
process.env.LANGFUSE_EVALUATOR_MEDIA_TRANSPORT,
diff --git a/worker/package.json b/worker/package.json
index 0c8d82f2bb..ae318d2206 100644
--- a/worker/package.json
+++ b/worker/package.json
@@ -58,6 +58,7 @@
"@prisma/instrumentation": "^6.19.3",
"ai-sdk-amazon-bedrock-v4": "npm:@ai-sdk/[email protected]",
"ai-sdk-anthropic-v4": "npm:@ai-sdk/[email protected]",
+ "ai-sdk-google-vertex-v4": "npm:@ai-sdk/[email protected]",
"ai-sdk-openai-compatible-v4": "npm:@ai-sdk/[email protected]",
"ai-sdk-openai-v4": "npm:@ai-sdk/[email protected]",
"bullmq": "^5.76.3",
diff --git a/worker/src/features/in-app-agent/runtime/agent.ts b/worker/src/features/in-app-agent/runtime/agent.ts
index 52da7e5ad1..c02dc1a238 100644
--- a/worker/src/features/in-app-agent/runtime/agent.ts
+++ b/worker/src/features/in-app-agent/runtime/agent.ts
@@ -1130,7 +1130,7 @@ async function createMastraAdapter(params: {
onToolExecutionEnd?: (toolCallId: string) => void;
stepLimitState: StepLimitState;
}) {
- const languageModel = createInAppAgentLanguageModel({
+ const languageModel = await createInAppAgentLanguageModel({
config: params.options.model,
awsProfile: params.awsProfile,
});
diff --git a/worker/src/features/in-app-agent/runtime/model.ts b/worker/src/features/in-app-agent/runtime/model.ts
index 3856645bca..3872e28082 100644
--- a/worker/src/features/in-app-agent/runtime/model.ts
+++ b/worker/src/features/in-app-agent/runtime/model.ts
@@ -1,5 +1,7 @@
import { createAmazonBedrock } from "ai-sdk-amazon-bedrock-v4";
import { createAnthropic } from "ai-sdk-anthropic-v4";
+import { createVertex } from "ai-sdk-google-vertex-v4";
+import { createVertexAnthropic } from "ai-sdk-google-vertex-v4/anthropic";
import { createOpenAICompatible } from "ai-sdk-openai-compatible-v4";
import { createOpenAI } from "ai-sdk-openai-v4";
@@ -9,19 +11,29 @@ import {
resolveLangfuseAIOpenAICall,
} from "@langfuse/shared/in-app-agent/server/openaiCompatibility";
import { env } from "@langfuse/shared/src/env";
-import { createDefaultBedrockProviderAuth } from "@langfuse/shared/src/server";
+import {
+ assertValidAnthropicVertexModelName,
+ createDefaultBedrockProviderAuth,
+ generateVertexAccessTokenFromADC,
+ isClaudeModel,
+ resolveVertexProjectIdFromADC,
+} from "@langfuse/shared/src/server";
const BEDROCK_CLAUDE_MODEL_ID_PART = "anthropic.claude";
const ANTHROPIC_CLAUDE_MODEL_ID_PART = "claude";
+// Existing Vertex connections default the location to "global" for both model
+// families; the in-app agent follows the same default.
+const DEFAULT_VERTEX_LOCATION = "global";
+
export type InAppAgentLanguageModel = ReturnType<
ReturnType<typeof createAmazonBedrock>
>;
-export function createInAppAgentLanguageModel(params: {
+export async function createInAppAgentLanguageModel(params: {
config: InAppAgentModelConfig;
awsProfile?: string;
-}): InAppAgentLanguageModel {
+}): Promise<InAppAgentLanguageModel> {
switch (params.config.provider) {
case "anthropic": {
const anthropic = createAnthropic({
@@ -41,6 +53,11 @@ export function createInAppAgentLanguageModel(params: {
params.config,
) as InAppAgentLanguageModel;
}
+ case "vertex": {
+ return (await createVertexInAppAgentLanguageModel(
+ params.config,
+ )) as InAppAgentLanguageModel;
+ }
case "bedrock": {
const bedrock = createAmazonBedrock({
...(params.config.region ? { region: params.config.region } : {}),
@@ -60,6 +77,36 @@ export function createInAppAgentLanguageModel(params: {
}
}
+async function createVertexInAppAgentLanguageModel(config: {
+ modelId: string;
+ location?: string;
+}) {
+ // Vertex authenticates through application default credentials, and the AI
+ // SDK needs the project spelled out for URL construction, so resolve it from
+ // the same credential chain. Project and token both come from shared so the
+ // worker never constructs google-auth-library (pnpm does not expose it).
+ const project = await resolveVertexProjectIdFromADC();
+ const location = config.location ?? DEFAULT_VERTEX_LOCATION;
+
+ if (isClaudeModel(config.modelId)) {
+ assertValidAnthropicVertexModelName(config.modelId);
+
+ const vertexAnthropic = createVertexAnthropic({
+ project,
+ location,
+ generateAuthToken: generateVertexAccessTokenFromADC,
+ });
+
+ return vertexAnthropic(
+ config.modelId as Parameters<typeof vertexAnthropic>[0],
+ );
+ }
+
+ const vertex = createVertex({ project, location });
+
+ return vertex(config.modelId as Parameters<typeof vertex>[0]);
+}
+
function createOpenAIInAppAgentLanguageModel(config: {
modelId: string;
apiKey: string;
@@ -152,6 +199,34 @@ export function getInAppAgentReasoningProviderOptions(
return forceResponsesReasoning(call.providerOptions);
}
+ case "vertex": {
+ // Claude on Vertex runs the Anthropic Messages model, which reads its
+ // canonical "anthropic" provider options regardless of the
+ // vertex-prefixed provider name.
+ //
+ // Gemini has no adaptive switch: thoughts surface only with an explicit
+ // thinkingBudget alongside includeThoughts, so it currently spends
+ // reasoning tokens without showing them. Wiring that up needs a default
+ // budget and should reuse the budget and clamp rules in
+ // buildThinkingConfig rather than restate them, so it stays out of here.
+ if (!isClaudeModel(config.modelId)) {
+ return undefined;
+ }
+
+ return {
+ anthropic: {
+ thinking: {
+ type: "adaptive" as const,
+ display: "summarized" as const,
+ },
+ // Adaptive thinking only engages when an effort level accompanies
+ // it; without this the model silently answers with no thinking at
+ // all. These models also reject thinking.type.enabled outright.
+ // The provider maps this onto the wire `output_config.effort`.
+ effort: "medium" as const,
+ },
+ };
+ }
case "bedrock":
return getBedrockReasoningProviderOptions(config.modelId);
default: {
diff --git a/worker/src/features/in-app-agent/runtime/reasoning.test.ts b/worker/src/features/in-app-agent/runtime/reasoning.test.ts
index a83abddcba..cea84d697b 100644
--- a/worker/src/features/in-app-agent/runtime/reasoning.test.ts
+++ b/worker/src/features/in-app-agent/runtime/reasoning.test.ts
@@ -1,5 +1,13 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+// Vertex Anthropic asks shared for the ADC project and OAuth token so the
+// worker never constructs google-auth-library (pnpm does not expose it).
+vi.mock("@langfuse/shared/src/server", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@langfuse/shared/src/server")>()),
+ resolveVertexProjectIdFromADC: async () => "adc-project",
+ generateVertexAccessTokenFromADC: async () => "fake-gcp-token",
+}));
+
import { env } from "@langfuse/shared/src/env";
import {
createInAppAgentLanguageModel,
@@ -70,7 +78,7 @@ describe("OpenAI Chat Completions request shape", () => {
const { calls, fetch } = createCaptureFetch(OPENAI_CHAT_RESPONSE);
vi.stubGlobal("fetch", fetch);
- const model = createInAppAgentLanguageModel({ config });
+ const model = await createInAppAgentLanguageModel({ config });
await model.doGenerate({
prompt: userPrompt(),
providerOptions: getInAppAgentReasoningProviderOptions(config),
@@ -96,7 +104,7 @@ describe("OpenAI Chat Completions request shape", () => {
const { calls, fetch } = createCaptureFetch(OPENAI_CHAT_RESPONSE);
vi.stubGlobal("fetch", fetch);
- const model = createInAppAgentLanguageModel({ config });
+ const model = await createInAppAgentLanguageModel({ config });
const prompt = [
{ role: "system" as const, content: "You are the Langfuse assistant." },
{
@@ -143,7 +151,7 @@ describe("OpenAI Responses request shape", () => {
const { calls, fetch } = createCaptureFetch(OPENAI_RESPONSES_RESPONSE);
vi.stubGlobal("fetch", fetch);
- const model = createInAppAgentLanguageModel({ config });
+ const model = await createInAppAgentLanguageModel({ config });
await model.doGenerate({
prompt: userPrompt(),
providerOptions: getInAppAgentReasoningProviderOptions(config),
@@ -171,7 +179,7 @@ describe("OpenAI Responses request shape", () => {
const { calls, fetch } = createCaptureFetch(OPENAI_RESPONSES_RESPONSE);
vi.stubGlobal("fetch", fetch);
- const model = createInAppAgentLanguageModel({ config });
+ const model = await createInAppAgentLanguageModel({ config });
const prompt = [
{ role: "system" as const, content: "You are the Langfuse assistant." },
{
@@ -225,7 +233,7 @@ describe("OpenAI Responses request shape", () => {
const { calls, fetch } = createCaptureFetch(OPENAI_RESPONSES_RESPONSE);
vi.stubGlobal("fetch", fetch);
- const model = createInAppAgentLanguageModel({ config });
+ const model = await createInAppAgentLanguageModel({ config });
await model.doGenerate({
prompt: userPrompt(),
providerOptions: getInAppAgentReasoningProviderOptions(config),
@@ -254,7 +262,7 @@ describe("OpenAI Responses request shape", () => {
const { calls, fetch } = createCaptureFetch(OPENAI_RESPONSES_RESPONSE);
vi.stubGlobal("fetch", fetch);
- const model = createInAppAgentLanguageModel({ config });
+ const model = await createInAppAgentLanguageModel({ config });
await model.doGenerate({
prompt: [
{ role: "system" as const, content: "You are the Langfuse assistant." },
@@ -287,7 +295,7 @@ describe("OpenAI Responses request shape", () => {
const { calls, fetch } = createCaptureFetch(OPENAI_RESPONSES_RESPONSE);
vi.stubGlobal("fetch", fetch);
- const model = createInAppAgentLanguageModel({ config });
+ const model = await createInAppAgentLanguageModel({ config });
await model.doGenerate({
prompt: userPrompt(),
providerOptions: getInAppAgentReasoningProviderOptions(config),
@@ -328,7 +336,7 @@ describe("Anthropic Messages request shape", () => {
});
vi.stubGlobal("fetch", fetch);
- const model = createInAppAgentLanguageModel({ config });
+ const model = await createInAppAgentLanguageModel({ config });
await model.doGenerate({
prompt: userPrompt(),
providerOptions: getInAppAgentReasoningProviderOptions(config),
@@ -391,6 +399,100 @@ function userPrompt() {
];
}
+describe("getInAppAgentReasoningProviderOptions on Vertex", () => {
+ // Claude on Vertex runs the Anthropic Messages model, so it takes the same
+ // canonical "anthropic" provider options as the direct Anthropic path even
+ // though the provider name is "vertex.anthropic.messages".
+ it.each([
+ "claude-sonnet-4-5@20250929",
+ "claude-opus-4-8",
+ "claude-haiku-4-5@20251001",
+ ])("returns adaptive summarized thinking for %s", (modelId) => {
+ expect(
+ getInAppAgentReasoningProviderOptions({
+ provider: "vertex",
+ modelId,
+ titleModelId: modelId,
+ location: "us-east5",
+ }),
+ ).toEqual({
+ anthropic: {
+ thinking: { type: "adaptive", display: "summarized" },
+ effort: "medium",
+ },
+ });
+ });
+
+ it("returns undefined for a Gemini model", () => {
+ expect(
+ getInAppAgentReasoningProviderOptions({
+ provider: "vertex",
+ modelId: "gemini-2.5-pro",
+ titleModelId: "gemini-2.5-flash",
+ }),
+ ).toBeUndefined();
+ });
+});
+
+describe("Vertex Claude request shape", () => {
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ });
+
+ it("keeps adaptive summarized thinking on the Vertex rawPredict body", async () => {
+ // Claude on Vertex is the Anthropic Messages model behind a rawPredict
+ // URL: the version moves into the body and the model into the URL. Capture
+ // the real SDK request so a provider change that drops thinking.display —
+ // or the ADC-resolved project — fails here rather than in production.
+ const config = {
+ provider: "vertex" as const,
+ modelId: "claude-sonnet-4-5@20250929",
+ titleModelId: "gemini-2.5-flash",
+ location: "us-east5",
+ };
+ const { calls, fetch } = createCaptureFetch({
+ id: "msg_1",
+ type: "message",
+ role: "assistant",
+ model: config.modelId,
+ content: [{ type: "text", text: "ok" }],
+ stop_reason: "end_turn",
+ stop_sequence: null,
+ usage: { input_tokens: 1, output_tokens: 1 },
+ });
+ vi.stubGlobal("fetch", fetch);
+
+ const model = await createInAppAgentLanguageModel({ config });
+ await model.doGenerate({
+ prompt: [
+ {
+ role: "user",
+ content: [{ type: "text", text: "hi" }],
+ },
+ ],
+ providerOptions: getInAppAgentReasoningProviderOptions(config),
+ });
+
+ expect(calls).toHaveLength(1);
+ expect(calls[0]?.headers.get("authorization")).toBe(
+ "Bearer fake-gcp-token",
+ );
+ expect(decodeURIComponent(calls[0]?.url ?? "")).toBe(
+ "https://us-east5-aiplatform.googleapis.com/v1/projects/adc-project/locations/us-east5/publishers/anthropic/models/claude-sonnet-4-5@20250929:rawPredict",
+ );
+ expect(calls[0]?.body.thinking).toEqual({
+ type: "adaptive",
+ display: "summarized",
+ });
+ // Adaptive thinking is inert without an effort level: the model answers
+ // with no thinking at all, and these models reject thinking.type.enabled,
+ // so this field is what actually turns reasoning on.
+ expect(calls[0]?.body.output_config).toEqual({ effort: "medium" });
+ expect(calls[0]?.body.anthropic_version).toBeTruthy();
+ expect(calls[0]?.body.model).toBeUndefined();
+ });
+});
+
function createCaptureFetch(response: unknown) {
const calls: Array<{
url: string;