Skip to content

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.

Marketplace preview gains the vertex-gemini anchor rung

nirholasedfe4b54fd31
diff --git a/api/marketplace/[action].js b/api/marketplace/[action].js
index 266a09ad7..2f36a669e 100644
--- a/api/marketplace/[action].js
+++ b/api/marketplace/[action].js
@@ -24,6 +24,12 @@ import { publicUrl, thumbnailUrl } from '../_lib/r2.js';
import { pedigreeScore } from '../_lib/genome.js';
import { clientIp, limits } from '../_lib/rate-limit.js';
import { markProviderCooldown, AUTH_COOLDOWN_SECONDS } from '../_lib/provider-health.js';
+import {
+ vertexGeminiAvailable,
+ vertexGeminiModel,
+ vertexGeminiChatUrl,
+ vertexGeminiHeaders,
+} from '../_lib/vertex-gemini.js';
import { getSkillPrices, skillPriceMap } from '../_lib/skill-price-cache.js';
import { viewerNftGatedSkills } from '../_lib/nft-gate.js';
import { z } from 'zod';
@@ -982,9 +988,11 @@ async function handlePreview(req, res, id) {
break;
}
try {
+ // Anchor routes mint per-request OAuth headers; keyed routes are static.
+ const headers = route.getHeaders ? await route.getHeaders() : route.headers;
upstream = await fetch(route.url, {
method: 'POST',
- headers: route.headers,
+ headers,
body: JSON.stringify(route.buildPayload({ systemPrompt, history })),
signal: AbortSignal.timeout(Math.min(22_000, budgetLeft())),
});
@@ -1071,7 +1079,7 @@ async function handlePreview(req, res, id) {
// 4. anthropic — paid backstop
// 5. openai — paid backstop (account may be over quota)
// 6. grok — paid backstop (xAI, budget tier)
-function buildPreviewRoutes() {
+export function buildPreviewRoutes() {
const order = ['groq', 'openrouter', 'nvidia', 'anthropic', 'openai', 'grok'];
const routes = [];
for (const name of order) {
@@ -1118,6 +1126,27 @@ function buildPreviewRoutes() {
});
}
}
+ // Keyless funded anchor (GCP credits): the one lane that stays up when every
+ // free tier throttles at once and the paid keys are dead. Strict tail — never
+ // a primary — mirroring chat.js / llm.js providerChain semantics. Headers are
+ // minted per attempt (OAuth token), so this route carries getHeaders instead
+ // of a static headers object.
+ if (vertexGeminiAvailable()) {
+ const model = vertexGeminiModel();
+ routes.push({
+ name: 'vertex-gemini',
+ model,
+ url: vertexGeminiChatUrl(),
+ style: 'openai',
+ getHeaders: vertexGeminiHeaders,
+ buildPayload: ({ systemPrompt, history }) => ({
+ model,
+ max_tokens: 512,
+ messages: [{ role: 'system', content: systemPrompt }, ...history],
+ stream: true,
+ }),
+ });
+ }
return routes;
}
diff --git a/tests/api/llm-vertex-anchor-surfaces.test.js b/tests/api/llm-vertex-anchor-surfaces.test.js
index a8e401d87..cf13e77b8 100644
--- a/tests/api/llm-vertex-anchor-surfaces.test.js
+++ b/tests/api/llm-vertex-anchor-surfaces.test.js
@@ -280,3 +280,40 @@ describe('anthropic-proxy (api/llm/anthropic.js): model fallback anchor', () =>
expect(chain.filter((m) => m === 'google/gemini-2.5-flash')).toHaveLength(1);
});
});
+
+describe('marketplace preview (api/marketplace/[action].js): buildPreviewRoutes anchor', () => {
+ it('appends a keyless vertex-gemini tail route when a GCP project is set', async () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ process.env.GROQ_API_KEY = 'gk';
+ process.env.OPENAI_API_KEY = 'ok';
+ const { buildPreviewRoutes } = await import('../../api/marketplace/[action].js');
+ const routes = buildPreviewRoutes();
+ const last = routes[routes.length - 1];
+ expect(last.name).toBe('vertex-gemini');
+ expect(last.url).toBe(vertexGeminiChatUrl());
+ expect(typeof last.getHeaders).toBe('function');
+ // Never a primary: keyed providers still lead.
+ expect(routes[0].name).toBe('groq');
+ });
+
+ it('keeps previews alive on a keyless deploy (anchor is the whole chain)', async () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ const { buildPreviewRoutes } = await import('../../api/marketplace/[action].js');
+ const routes = buildPreviewRoutes();
+ expect(routes).toHaveLength(1);
+ expect(routes[0].name).toBe('vertex-gemini');
+ const payload = routes[0].buildPayload({
+ systemPrompt: 'be brief',
+ history: [{ role: 'user', content: 'hi' }],
+ });
+ expect(payload.model).toBe(vertexGeminiModel());
+ expect(payload.messages[0]).toEqual({ role: 'system', content: 'be brief' });
+ });
+
+ it('is absent without a GCP project', async () => {
+ process.env.GROQ_API_KEY = 'gk';
+ const { buildPreviewRoutes } = await import('../../api/marketplace/[action].js');
+ const routes = buildPreviewRoutes();
+ expect(routes.map((r) => r.name)).not.toContain('vertex-gemini');
+ });
+});