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.

docs(env): document QUICKNODE_RPC_URL, DRPC/ANKR keys in .env.example

nirholas0f101cd467bd
diff --git a/.env.example b/.env.example
index a5ea495b6..7496faf70 100644
--- a/.env.example
+++ b/.env.example
@@ -1028,12 +1028,30 @@ SOLANA_MAINNET_RPC=
# Comma-separated list of fallback RPC URLs tried in order on primary failure.
# Used by api/_lib/solana/rpc-fallback.js.
SOLANA_RPC_FALLBACK_URLS=
-# Comma-separated PAID metered endpoints held in reserve (e.g. the Quicknode
-# credit-funded endpoint). Tried dead LAST, after every free/keyless public
-# node, so their monthly quota is only spent when the entire free chain is
-# down or throttled. Mainnet only.
+# Comma-separated PAID metered endpoints held in reserve. Tried dead LAST,
+# after every free/keyless public node, so their monthly quota is only spent
+# when the entire free chain is down or throttled. Mainnet only. NOTE: for a
+# dedicated paid endpoint you actually want in rotation, prefer QUICKNODE_RPC_URL
+# below (high-priority lane) over this reserve slot.
SOLANA_RPC_LAST_RESORT_URLS=
+# A single dedicated QuickNode endpoint URL (the access token is embedded in the
+# path, so this is a full URL, not an api-key). Placed HIGH in the chain by
+# api/_lib/solana/connection.js (right after SOLANA_RPC_URL and ahead of the
+# shared-key providers Helius/Alchemy), so a paid, reliable node absorbs load
+# first instead of sitting behind the flaky public tail. Its WSS is derived by
+# https:->wss:, which matches QuickNode's own wss:// host/path. Get one at
+# https://quicknode.com (Solana Mainnet). Use QUICKNODE_RPC_URL_DEVNET for devnet.
+QUICKNODE_RPC_URL=
+QUICKNODE_RPC_URL_DEVNET=
+
+# dRPC + Ankr authenticated keys (both sunset keyless access). When set, they are
+# added to the Solana RPC chain in their authenticated form as extra keyed lanes
+# after Helius/Alchemy. Keyless entries are deliberately omitted (guaranteed 403).
+# dRPC: https://drpc.org · Ankr: https://www.ankr.com/rpc.
+DRPC_API_KEY=
+ANKR_API_KEY=
+
# Per-chain RPC aliases consulted by /api/permissions/[action] when the
# canonical RPC_URL_<chainId> isn't set. Useful when sharing env across the
# permissions relayer and a separate test runner.
diff --git a/api/chat.js b/api/chat.js
index d11b9410b..76f9b791d 100644
--- a/api/chat.js
+++ b/api/chat.js
@@ -77,6 +77,22 @@ const DEFAULT_OPENAI_MODEL = PROVIDER_MODEL_DEFAULTS.openai;
const DEFAULT_MAX_TOKENS = 1024;
const HARD_MAX_TOKENS = 4096;
+// Vertex Gemini (GCP credits) via its OpenAI-compatible endpoint — the same rung
+// api/_lib/llm.js exposes as vertexGeminiProvider(). Serves as the credits-funded
+// last-resort anchor: it needs no third-party quota, so a signed-out /api/chat
+// request can never 503 just because groq/openrouter/nvidia are all throttled at
+// once (that was the whole point of adding 'vertex-gemini' to ANON_PROVIDER_LIST,
+// but the route was never wired into PROVIDERS/providerOrder, so the anchor was
+// dead). Model + location follow the same env knobs as the llm.js rung.
+const VERTEX_GEMINI_CHAT_MODEL = process.env.VERTEX_GEMINI_MODEL || 'google/gemini-2.5-flash';
+function vertexGeminiChatUrl() {
+ 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`;
+ return `https://${host}/v1beta1/projects/${project}/locations/${location}/endpoints/openapi/chat/completions`;
+}
+
const PROVIDERS = {
anthropic: {
envKey: 'ANTHROPIC_API_KEY',
@@ -93,6 +109,17 @@ const PROVIDERS = {
defaultModel: DEFAULT_ANTHROPIC_MODEL,
style: 'vertex-anthropic',
},
+ // Vertex-served Gemini (GCP credits), OpenAI-compatible wire format. No envKey
+ // — availability is gated by GOOGLE_CLOUD_PROJECT and the OAuth bearer token is
+ // minted per request in makeRoute (resolveHeaders), exactly like the keyless
+ // `vertex` route above. Never auto-selected as a primary route (it sits at the
+ // tail of providerOrder()); reached only via failover, where it is the
+ // credits-funded anchor that keeps anonymous chat alive when every free lane is
+ // rate-limited at once.
+ 'vertex-gemini': {
+ defaultModel: VERTEX_GEMINI_CHAT_MODEL,
+ style: 'vertex-gemini',
+ },
openrouter: {
envKey: 'OPENROUTER_API_KEY',
defaultModel: DEFAULT_OPENROUTER_MODEL,
@@ -997,21 +1024,42 @@ async function governActions(actions, userMessage) {
// ── Provider selection ───────────────────────────────────────────────────────
+// Keyless Vertex routes carry no API key — their bearer token is minted per
+// request (makeRoute.resolveHeaders), and availability is gated by config, not an
+// env key: vertex-anthropic by vertexClaudeEnabled(), vertex-gemini by a GCP
+// project. Centralized so pickProvider and buildFallbackChain gate identically.
+const KEYLESS_VERTEX = new Set(['vertex', 'vertex-gemini']);
+function keylessVertexAvailable(name) {
+ if (name === 'vertex') return vertexClaudeEnabled();
+ if (name === 'vertex-gemini') return Boolean(process.env.GOOGLE_CLOUD_PROJECT);
+ return false;
+}
+
// Effective provider try-order. Vertex-served Claude is injected per flags:
// VERTEX_CLAUDE_PRIMARY → Vertex leads the whole ladder (before the free
// lanes) — the platform's default brain becomes real Claude on GCP credits.
// VERTEX_CLAUDE_ENABLED (not primary) → Vertex sits in the paid tier, just
// ahead of first-party Anthropic (GCP credits before a paid Anthropic key).
-// Both off → DEFAULT_PROVIDER_ORDER is returned verbatim, so routing is
-// byte-identical to today.
-function providerOrder() {
- if (vertexClaudePrimary()) return ['vertex', ...DEFAULT_PROVIDER_ORDER];
+// Both off → DEFAULT_PROVIDER_ORDER is returned verbatim.
+// In every case the credits-funded vertex-gemini anchor is appended at the TAIL
+// (when GOOGLE_CLOUD_PROJECT is set): never auto-selected as a primary route, but
+// always present as the last-resort rung so a failover chain — anon or authed —
+// reaches a quota-free provider before it surfaces a capacity error.
+export function providerOrder() {
+ const withGeminiAnchor = (order) =>
+ process.env.GOOGLE_CLOUD_PROJECT && !order.includes('vertex-gemini')
+ ? [...order, 'vertex-gemini']
+ : order;
+ if (vertexClaudePrimary()) return withGeminiAnchor(['vertex', ...DEFAULT_PROVIDER_ORDER]);
if (vertexClaudeEnabled()) {
const i = DEFAULT_PROVIDER_ORDER.indexOf('anthropic');
- if (i === -1) return [...DEFAULT_PROVIDER_ORDER, 'vertex'];
- return [...DEFAULT_PROVIDER_ORDER.slice(0, i), 'vertex', ...DEFAULT_PROVIDER_ORDER.slice(i)];
+ const base =
+ i === -1
+ ? [...DEFAULT_PROVIDER_ORDER, 'vertex']
+ : [...DEFAULT_PROVIDER_ORDER.slice(0, i), 'vertex', ...DEFAULT_PROVIDER_ORDER.slice(i)];
+ return withGeminiAnchor(base);
}
- return DEFAULT_PROVIDER_ORDER;
+ return withGeminiAnchor(DEFAULT_PROVIDER_ORDER);
}
function pickProvider(requested, model, userKeys = {}, cooldown = new Map()) {
@@ -1037,8 +1085,8 @@ function pickProvider(requested, model, userKeys = {}, cooldown = new Map()) {
// Vertex has no API key — availability is gated by vertexClaudeEnabled()
// and its bearer token is minted per request (makeRoute.resolveHeaders).
// A sentinel keeps the shared `usingHostKey`/route plumbing below intact.
- const apiKey = name === 'vertex' ? 'vertex' : userKeys[name] || process.env[cfg.envKey];
- if (name === 'vertex' ? !vertexClaudeEnabled() : !apiKey) continue;
+ const apiKey = KEYLESS_VERTEX.has(name) ? 'vertex' : userKeys[name] || process.env[cfg.envKey];
+ if (KEYLESS_VERTEX.has(name) ? !keylessVertexAvailable(name) : !apiKey) continue;
if (skipCooldown && cooldown.has(name) && (name !== requested || cooldown.get(name) === 'auth'))
continue;
// watsonx needs both a key and a project/space scope to serve a model;
@@ -1051,7 +1099,7 @@ function pickProvider(requested, model, userKeys = {}, cooldown = new Map()) {
// or NVIDIA request would 400 every chat.
const chosenModel =
(requested === name && model) ||
- (name === 'watsonx' || name === 'orchestrate' || name === 'vertex'
+ (name === 'watsonx' || name === 'orchestrate' || KEYLESS_VERTEX.has(name)
? cfg.defaultModel
: envPinnedModelFor(name) || cfg.defaultModel);
const route = makeRoute(name, cfg, apiKey, chosenModel);
@@ -1115,7 +1163,7 @@ function eligibleAsFallback(modelId) {
return meta.tools === true && !meta.moderationGated;
}
-function buildFallbackChain(primary, userKeys = {}, cooldown = new Map()) {
+export function buildFallbackChain(primary, userKeys = {}, cooldown = new Map()) {
const chain = [primary];
const seen = new Set([`${primary.name}:${primary.model}`]);
@@ -1126,8 +1174,8 @@ function buildFallbackChain(primary, userKeys = {}, cooldown = new Map()) {
if (!eligibleAsFallback(model)) return;
const cfg = PROVIDERS[name];
// Vertex is keyless — gated by vertexClaudeEnabled(); token minted per call.
- const apiKey = name === 'vertex' ? 'vertex' : userKeys[name] || process.env[cfg.envKey];
- if (name === 'vertex' ? !vertexClaudeEnabled() : !apiKey) return;
+ const apiKey = KEYLESS_VERTEX.has(name) ? 'vertex' : userKeys[name] || process.env[cfg.envKey];
+ if (KEYLESS_VERTEX.has(name) ? !keylessVertexAvailable(name) : !apiKey) return;
if (name === 'watsonx' && !watsonxConfig().configured) return;
if (name === 'orchestrate' && !orchestrateConfig().configured) return;
seen.add(key);
@@ -1178,6 +1226,27 @@ function makeRoute(name, cfg, apiKey, model) {
}),
};
}
+ if (cfg.style === 'vertex-gemini') {
+ // Gemini on Vertex through the OpenAI-compatible endpoint: OpenAI-shaped body
+ // and reply (so style 'openai' + streamOpenAI parse it verbatim), but the
+ // model rides in the body, the endpoint is the Vertex openapi URL, and the
+ // bearer token is minted per request. `via` is the distinct telemetry label.
+ return {
+ name,
+ via: 'vertex-gemini',
+ model,
+ url: vertexGeminiChatUrl(),
+ style: 'openai',
+ resolveHeaders: () => vertexRequestHeaders(),
+ buildPayload: ({ systemPrompt, history, maxTokens, includeTools = true }) => ({
+ model,
+ max_tokens: maxTokens,
+ messages: [{ role: 'system', content: systemPrompt }, ...history],
+ ...(includeTools ? { tools: OPENAI_TOOLS, tool_choice: 'auto' } : {}),
+ stream: true,
+ }),
+ };
+ }
if (cfg.style === 'anthropic') {
return {
name,
diff --git a/tests/api/chat-vertex-anchor.test.js b/tests/api/chat-vertex-anchor.test.js
new file mode 100644
index 000000000..fded89e26
--- /dev/null
+++ b/tests/api/chat-vertex-anchor.test.js
@@ -0,0 +1,74 @@
+// Regression guard for the anonymous-chat credits anchor (api/chat.js).
+//
+// ANON_PROVIDER_LIST (chat-models.js) lists 'vertex-gemini' as the last-resort
+// anchor that keeps signed-out /api/chat alive when groq/openrouter/nvidia are
+// all rate-limited at once. That list is only a FILTER, though — it can keep a
+// route in the fallback chain but can never add one. For a long window the route
+// was in the list but never in PROVIDERS or providerOrder(), so the anchor was
+// dead and anon chat 503'd on a triple free-lane throttle. These tests lock the
+// wiring: the anchor must be present in the try-order AND constructible as a real
+// route, and must stay absent (no behavior change) when no GCP project is set.
+
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { ANON_PROVIDER_LIST } from '../../api/_lib/chat-models.js';
+import { providerOrder, buildFallbackChain } from '../../api/chat.js';
+
+const saved = {};
+function setEnv(k, v) {
+ saved[k] = process.env[k];
+ if (v === undefined) delete process.env[k];
+ else process.env[k] = v;
+}
+beforeEach(() => {
+ // Isolate the Vertex flags so the order is deterministic.
+ for (const k of ['GOOGLE_CLOUD_PROJECT', 'VERTEX_CLAUDE_ENABLED', 'VERTEX_CLAUDE_PRIMARY', 'GOOGLE_CLOUD_LOCATION_GEMINI']) {
+ setEnv(k, undefined);
+ }
+});
+afterEach(() => {
+ for (const [k, v] of Object.entries(saved)) {
+ if (v === undefined) delete process.env[k];
+ else process.env[k] = v;
+ }
+});
+
+describe('anonymous-chat vertex-gemini anchor wiring', () => {
+ it('providerOrder appends vertex-gemini at the tail when a GCP project is set', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ const order = providerOrder();
+ expect(order).toContain('vertex-gemini');
+ expect(order[order.length - 1]).toBe('vertex-gemini'); // last resort, never leads
+ });
+
+ it('omits the anchor entirely when no GCP project is configured (no behavior change)', () => {
+ const order = providerOrder();
+ expect(order).not.toContain('vertex-gemini');
+ });
+
+ it('the anchor survives the anonymous clamp — it is in ANON_PROVIDER_LIST', () => {
+ // The handler filters the fallback chain to ANON_PROVIDER_LIST for signed-out
+ // traffic; the anchor is only useful if that filter keeps it.
+ expect(ANON_PROVIDER_LIST).toContain('vertex-gemini');
+ });
+
+ it('buildFallbackChain constructs a real, keyless vertex-gemini route (the piece that was missing)', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ const primary = { name: 'groq', model: 'llama-3.3-70b-versatile' };
+ const chain = buildFallbackChain(primary, {}, new Map());
+ const anchor = chain.find((r) => r.name === 'vertex-gemini');
+ expect(anchor).toBeTruthy();
+ // OpenAI-compatible Vertex endpoint, model in the body, token minted per call.
+ expect(anchor.url).toContain('aiplatform.googleapis.com');
+ expect(anchor.url).toContain('test-project');
+ expect(anchor.model).toBe(process.env.VERTEX_GEMINI_MODEL || 'google/gemini-2.5-flash');
+ expect(anchor.style).toBe('openai');
+ expect(typeof anchor.resolveHeaders).toBe('function');
+ expect(anchor.headers).toBeUndefined(); // keyless: no static Authorization header
+ });
+
+ it('does not construct a vertex-gemini route without a GCP project', () => {
+ const primary = { name: 'groq', model: 'llama-3.3-70b-versatile' };
+ const chain = buildFallbackChain(primary, {}, new Map());
+ expect(chain.find((r) => r.name === 'vertex-gemini')).toBeUndefined();
+ });
+});