Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat(gcp): probe Vertex Gemini/Claude in LLM health, keep 4 CPU workers warm
nirholasc760987da224
diff --git a/api/_lib/llm-health.js b/api/_lib/llm-health.jsindex a075a1283..6c5abb403 100644--- a/api/_lib/llm-health.js+++ b/api/_lib/llm-health.js@@ -11,11 +11,21 @@// before it degrades the product.//// Probed providers mirror the paid tier of the routing chain:-// • OpenRouter (primary, env.OPENROUTER_API_KEY) — leads the paid path-// • Anthropic (env.ANTHROPIC_API_KEY) — paid backstop-// • OpenAI (env.OPENAI_API_KEY) — paid backstop-// A provider with no key is simply not probed (omitted from the report) — it is-// not "down", it is "not part of this deployment".+// • OpenRouter (primary, env.OPENROUTER_API_KEY) — leads the paid path+// • Anthropic (env.ANTHROPIC_API_KEY) — paid backstop+// • OpenAI (env.OPENAI_API_KEY) — paid backstop+// • Vertex Gemini (GOOGLE_CLOUD_PROJECT) — GCP-credit-billed anchor+// • Vertex Anthropic (VERTEX_CLAUDE_ENABLED=1) — GCP-credit-billed Claude+// A provider with no key/config is simply not probed (omitted from the report) —+// it is not "down", it is "not part of this deployment".+//+// The two Vertex rungs matter here specifically because llm.js's real chain+// (providerChain()) already reaches them whenever GOOGLE_CLOUD_PROJECT is set —+// they are the reliability anchor that survives a same-day outage of all three+// third-party paid keys above. Before these were added, this probe (and the+// /api/llm/health dashboard it backs) would report `down`/`degraded` during+// exactly the outage Vertex was already absorbing for real users — a false+// alarm hiding the fact that the platform was fine.//// Statuses per provider: 'ok' (2xx) | 'error' (timeout, unreachable, or non-2xx,// e.g. a 402 out-of-credits or a 401 bad key). `overall` is 'ok' when every@@ -27,6 +37,7 @@// gated, at GET /api/llm/health.import { env } from './env.js';+import { vertexClaudeEnabled, vertexMessagesUrl, vertexRequestHeaders, toVertexBody } from './vertex-claude.js';const PROBE_TIMEOUT_MS = 5_000;@@ -35,6 +46,9 @@ const PROBE_TIMEOUT_MS = 5_000;const OPENROUTER_MODEL = 'openai/gpt-5.4-nano';const ANTHROPIC_MODEL = 'claude-haiku-4-5-20251001';const OPENAI_MODEL = 'gpt-5.4-nano';+// Same model ids llm.js's real chain uses for these two rungs — see+// vertexGeminiProvider()/vertexAnthropicProvider() there.+const VERTEX_GEMINI_MODEL = process.env.VERTEX_GEMINI_MODEL || 'google/gemini-2.5-flash';// fetch with a hard 5s timeout; returns the Response (or null on transport// error) plus the measured round-trip so the report can surface latency.@@ -80,6 +94,42 @@ async function probeAnthropic({ key, model }) {return judge(r, model);}+// Vertex probes authenticate with a GCP OAuth bearer token (vertexRequestHeaders)+// instead of a static API key, so a token-exchange failure (no service-account+// credentials, no aiplatform IAM) is itself a real, reportable 'error' verdict —+// caught here rather than left to throw uncaught.+async function probeVertexGemini() {+ const project = process.env.GOOGLE_CLOUD_PROJECT;+ const location = process.env.GOOGLE_CLOUD_LOCATION_GEMINI || 'global';+ const host = location === 'global' ? 'aiplatform.googleapis.com' : `${location}-aiplatform.googleapis.com`;+ const url = `https://${host}/v1beta1/projects/${project}/locations/${location}/endpoints/openapi/chat/completions`;+ try {+ const headers = { 'content-type': 'application/json', ...(await vertexRequestHeaders()) };+ const r = await timedFetch(url, {+ method: 'POST',+ headers,+ body: JSON.stringify({ model: VERTEX_GEMINI_MODEL, max_tokens: 1, messages: [{ role: 'user', content: 'ping' }] }),+ });+ return judge(r, VERTEX_GEMINI_MODEL);+ } catch (err) {+ return { status: 'error', error: `token exchange failed: ${err?.message || 'unknown'}`, latencyMs: 0 };+ }+}++async function probeVertexAnthropic({ model }) {+ try {+ const headers = await vertexRequestHeaders();+ const r = await timedFetch(vertexMessagesUrl(model, { stream: false }), {+ method: 'POST',+ headers,+ body: JSON.stringify(toVertexBody({ model, max_tokens: 1, messages: [{ role: 'user', content: 'ping' }] })),+ });+ return judge(r, model);+ } catch (err) {+ return { status: 'error', error: `token exchange failed: ${err?.message || 'unknown'}`, latencyMs: 0 };+ }+}+// Probe every configured paid provider in parallel and fold the per-provider// verdicts into one `overall`. Returns { [provider]: verdict, ..., overall }.export async function probeLlmHealth() {@@ -108,6 +158,16 @@ export async function probeLlmHealth() {}),]);}+ // Same gate llm.js's real chain uses (providerChain(): `if+ // (process.env.GOOGLE_CLOUD_PROJECT) chain.push(vertexGeminiProvider())`) —+ // probed whenever the chain would actually reach for it, not behind a+ // separate flag.+ if (process.env.GOOGLE_CLOUD_PROJECT) {+ probes.push(['vertex-gemini', probeVertexGemini()]);+ }+ if (vertexClaudeEnabled()) {+ probes.push(['vertex-anthropic', probeVertexAnthropic({ model: ANTHROPIC_MODEL })]);+ }const verdicts = await Promise.all(probes.map(async ([name, p]) => [name, await p]));const report = Object.fromEntries(verdicts);diff --git a/tests/api/llm-health-vertex.test.js b/tests/api/llm-health-vertex.test.jsnew file mode 100644index 000000000..67ace182d--- /dev/null+++ b/tests/api/llm-health-vertex.test.js@@ -0,0 +1,95 @@+// api/_lib/llm-health.js — Vertex Gemini / Vertex Anthropic probes.+//+// Regression this closes: llm.js's real provider chain reaches Vertex Gemini+// whenever GOOGLE_CLOUD_PROJECT is set (the platform's actual reliability+// anchor — see providerChain() in llm.js), but this health probe never knew+// Vertex existed, so /api/llm/health reported 'down'/'degraded' during an+// outage of OpenRouter/Anthropic/OpenAI even when Vertex was transparently+// keeping every user-facing AI feature alive. These tests pin that the probe+// now mirrors the real chain's gate exactly.++import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';++vi.mock('../../api/_lib/env.js', () => ({+ env: new Proxy({}, { get: (_t, k) => process.env[k] }),+}));+vi.mock('../../api/_lib/gcp-auth.js', () => ({+ getGcpAccessToken: vi.fn(async () => 'fake-gcp-oauth-token'),+}));++const { probeLlmHealth } = await import('../../api/_lib/llm-health.js');+const { getGcpAccessToken } = await import('../../api/_lib/gcp-auth.js');++const ORIGINAL_ENV = { ...process.env };++beforeEach(() => {+ vi.restoreAllMocks();+ for (const k of ['OPENROUTER_API_KEY', 'ANTHROPIC_API_KEY', 'OPENAI_API_KEY', 'GOOGLE_CLOUD_PROJECT', 'VERTEX_CLAUDE_ENABLED']) {+ delete process.env[k];+ }+});+afterEach(() => {+ process.env = { ...ORIGINAL_ENV };+});++describe('probeLlmHealth — Vertex gating', () => {+ it('omits both Vertex rungs when GOOGLE_CLOUD_PROJECT is unset (unchanged pre-Vertex behavior)', async () => {+ const report = await probeLlmHealth();+ expect(report['vertex-gemini']).toBeUndefined();+ expect(report['vertex-anthropic']).toBeUndefined();+ expect(report.overall).toBe('unconfigured');+ });++ it('probes vertex-gemini whenever GOOGLE_CLOUD_PROJECT is set — the same gate providerChain() uses', async () => {+ process.env.GOOGLE_CLOUD_PROJECT = 'three-ws-prod';+ vi.spyOn(globalThis, 'fetch').mockResolvedValue({ ok: true, status: 200, statusText: 'OK' });++ const report = await probeLlmHealth();+ expect(report['vertex-gemini']).toMatchObject({ status: 'ok' });+ expect(report['vertex-anthropic']).toBeUndefined(); // VERTEX_CLAUDE_ENABLED not set+ expect(report.overall).toBe('ok');+ expect(getGcpAccessToken).toHaveBeenCalled();+ });++ it('probes vertex-anthropic only when VERTEX_CLAUDE_ENABLED=1 (matches vertexClaudeEnabled())', async () => {+ process.env.GOOGLE_CLOUD_PROJECT = 'three-ws-prod';+ process.env.VERTEX_CLAUDE_ENABLED = '1';+ vi.spyOn(globalThis, 'fetch').mockResolvedValue({ ok: true, status: 200, statusText: 'OK' });++ const report = await probeLlmHealth();+ expect(report['vertex-gemini']).toMatchObject({ status: 'ok' });+ expect(report['vertex-anthropic']).toMatchObject({ status: 'ok' });+ });++ it('reports a real error verdict — not an uncaught throw — when GCP token exchange fails', async () => {+ process.env.GOOGLE_CLOUD_PROJECT = 'three-ws-prod';+ getGcpAccessToken.mockRejectedValueOnce(new Error('no credentials configured'));++ const report = await probeLlmHealth();+ expect(report['vertex-gemini'].status).toBe('error');+ expect(report['vertex-gemini'].error).toMatch(/token exchange failed/);+ });++ it('reports vertex-gemini as a real outage signal (a genuine 500) rather than masking it', async () => {+ process.env.GOOGLE_CLOUD_PROJECT = 'three-ws-prod';+ vi.spyOn(globalThis, 'fetch').mockResolvedValue({ ok: false, status: 500, statusText: 'Internal Server Error' });++ const report = await probeLlmHealth();+ expect(report['vertex-gemini'].status).toBe('error');+ expect(report.overall).toBe('down');+ });++ it('folds Vertex into overall alongside third-party providers: down third-party + ok Vertex = degraded, not down', async () => {+ process.env.OPENAI_API_KEY = 'sk-test';+ process.env.GOOGLE_CLOUD_PROJECT = 'three-ws-prod';+ vi.spyOn(globalThis, 'fetch').mockImplementation(async (url) => {+ if (String(url).includes('openai.com')) return { ok: false, status: 429, statusText: 'Too Many Requests' };+ return { ok: true, status: 200, statusText: 'OK' }; // vertex-gemini+ });++ const report = await probeLlmHealth();+ expect(report.openai.status).toBe('error');+ expect(report['vertex-gemini'].status).toBe('ok');+ expect(report.overall).toBe('degraded');+ });+});diff --git a/workers/rembg/cloudbuild.yaml b/workers/rembg/cloudbuild.yamlindex b1fc7a00a..b2a172fc6 100644--- a/workers/rembg/cloudbuild.yaml+++ b/workers/rembg/cloudbuild.yaml@@ -4,7 +4,11 @@ substitutions:_SERVICE: rembg-service_REPO: rembg-service_GCS_BUCKET: three-ws-avatar-reconstructions- _MIN_INSTANCES: "0"+ # Kept warm (not scale-to-zero): this worker backs interactive material+ # editing (restyle_material) — a cold start here is a user-facing multi-second+ # stall mid-edit. CPU-only, no GPU, cheap to keep resident against the $100k+ # GCP credit pool. 2026-07-16.+ _MIN_INSTANCES: "1"_MAX_INSTANCES: "4"steps:diff --git a/workers/remesh/cloudbuild.yaml b/workers/remesh/cloudbuild.yamlindex f9399deea..c0d40fd6a 100644--- a/workers/remesh/cloudbuild.yaml+++ b/workers/remesh/cloudbuild.yaml@@ -4,7 +4,11 @@ substitutions:_SERVICE: remesh-service_REPO: remesh-service_GCS_BUCKET: three-ws-avatar-reconstructions- _MIN_INSTANCES: "0"+ # Kept warm (not scale-to-zero): this worker backs interactive material+ # editing (restyle_material) — a cold start here is a user-facing multi-second+ # stall mid-edit. CPU-only, no GPU, cheap to keep resident against the $100k+ # GCP credit pool. 2026-07-16.+ _MIN_INSTANCES: "1"_MAX_INSTANCES: "3"steps:diff --git a/workers/segment/cloudbuild.yaml b/workers/segment/cloudbuild.yamlindex 01b592b94..306ccee75 100644--- a/workers/segment/cloudbuild.yaml+++ b/workers/segment/cloudbuild.yaml@@ -4,7 +4,11 @@ substitutions:_SERVICE: segment-service_REPO: segment-service_GCS_BUCKET: three-ws-avatar-reconstructions- _MIN_INSTANCES: "0"+ # Kept warm (not scale-to-zero): this worker backs interactive material+ # editing (restyle_material) — a cold start here is a user-facing multi-second+ # stall mid-edit. CPU-only, no GPU, cheap to keep resident against the $100k+ # GCP credit pool. 2026-07-16.+ _MIN_INSTANCES: "1"_MAX_INSTANCES: "3"steps:diff --git a/workers/stylize/cloudbuild.yaml b/workers/stylize/cloudbuild.yamlindex c38be060c..8544cf086 100644--- a/workers/stylize/cloudbuild.yaml+++ b/workers/stylize/cloudbuild.yaml@@ -4,7 +4,11 @@ substitutions:_SERVICE: stylize-service_REPO: stylize-service_GCS_BUCKET: three-ws-avatar-reconstructions- _MIN_INSTANCES: "0"+ # Kept warm (not scale-to-zero): this worker backs interactive material+ # editing (restyle_material) — a cold start here is a user-facing multi-second+ # stall mid-edit. CPU-only, no GPU, cheap to keep resident against the $100k+ # GCP credit pool. 2026-07-16.+ _MIN_INSTANCES: "1"_MAX_INSTANCES: "3"steps: