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(llm): provider registry, pricing, and chat model updates
nirholas063a6a643eef
diff --git a/api/_lib/chat-models.js b/api/_lib/chat-models.jsindex c5667728d..f13872f6f 100644--- a/api/_lib/chat-models.js+++ b/api/_lib/chat-models.js@@ -78,6 +78,11 @@ export const MODEL_CATALOG = {'meta/llama-3.3-70b-instruct': { provider: 'nvidia', tools: true },'nvidia/llama-3.3-nemotron-super-49b-v1.5': { provider: 'nvidia', tools: true },+ // ── xAI Grok (paid; host or BYOK key) — OpenAI-compatible at api.x.ai ─────+ 'grok-4.5': { provider: 'grok', tools: true },+ 'grok-4.3': { provider: 'grok', tools: true },+ 'grok-4.1-fast': { provider: 'grok', tools: true },+// ── OpenAI (paid) — see operational note above; ranked last ───────────────'gpt-5.6-sol': { provider: 'openai', tools: true },'gpt-5.6-terra': { provider: 'openai', tools: true },@@ -154,6 +159,7 @@ export const PROVIDER_MODEL_DEFAULTS = {groq: 'llama-3.3-70b-versatile',nvidia: 'meta/llama-3.3-70b-instruct',openai: 'gpt-5.4-nano',+ grok: 'grok-4.5',};/**@@ -170,11 +176,13 @@ export const PROVIDER_MODEL_DEFAULTS = {* 4. anthropic — paid backstop; only reached when every free lane failed* (and currently 401s in prod — see operational note).* 5. openai — paid backstop; account over quota (see operational note).+ * 6. grok — paid backstop (xAI); usually reached only via an explicit+ * provider/model request or a BYOK key.* Providers without a configured key are skipped, so the effective ladder is* short in the common case. A provider in a health cooldown (see* api/_lib/provider-health.js) is also skipped for the cooldown window.*/-export const DEFAULT_PROVIDER_ORDER = ['groq', 'openrouter', 'nvidia', 'anthropic', 'openai'];+export const DEFAULT_PROVIDER_ORDER = ['groq', 'openrouter', 'nvidia', 'anthropic', 'openai', 'grok'];/*** OpenRouter sibling models for per-model rate-limit failover. OpenRouter'sdiff --git a/api/_lib/env.js b/api/_lib/env.jsindex 985eea7e0..3c53e451d 100644--- a/api/_lib/env.js+++ b/api/_lib/env.js@@ -520,6 +520,15 @@ export const env = {return opt('GROQ_API_KEY');},+ // xAI Grok API key (console.x.ai): paid OpenAI-compatible inference+ // (grok-4.5 flagship, grok-4.3 long-context, grok-4.1-fast budget).+ // Used by brain/chat, viewer chat, the shared LLM chain, and the embed+ // we-pay proxy. Accepts XAI_API_KEY as an alias. Optional: when unset,+ // Grok rungs are skipped and only BYOK Grok keys work.+ get GROK_API_KEY() {+ return opt('GROK_API_KEY') || opt('XAI_API_KEY');+ },+// Cerebras API key (cloud.cerebras.ai) — free-tier OpenAI-compatible Llama// 3.3 70B inference, extremely fast. Optional rung in the shared LLM chain// (api/_lib/llm.js); when unset the chain simply skips it.@@ -1133,7 +1142,7 @@ export const env = {},// Solana RPC URL — single source of truth for all Solana RPC calls.- // Set to a Helius/QuickNode/Triton URL in production to avoid public RPC rate limits.+ // Set to a Helius/Quicknode/Triton URL in production to avoid public RPC rate limits.get SOLANA_RPC_URL() {// Coalesce to the public endpoint when unset OR when a configured value is// malformed beyond repair — every direct consumer (fetch / new Connection)diff --git a/api/_lib/llm-pricing.js b/api/_lib/llm-pricing.jsindex 0e007026d..e9bd447e9 100644--- a/api/_lib/llm-pricing.js+++ b/api/_lib/llm-pricing.js@@ -33,6 +33,10 @@ const PRICE_PER_MTOK = {'gpt-5.3-codex': [1.75, 14],'o3-pro': [20, 80],'o3': [2, 8],+ // xAI Grok list prices (docs.x.ai, July 2026). 4.1-fast is the budget tier.+ 'grok-4.5': [2, 6],+ 'grok-4.3': [1.25, 2.5],+ 'grok-4.1-fast': [0.2, 0.5],// Deprecated OpenAI family — kept so historical usage_events still price.'gpt-4o-mini': [0.15, 0.6],'gpt-4o': [2.5, 10],diff --git a/api/_lib/llm.js b/api/_lib/llm.jsindex 3d73ccede..93d9ff6af 100644--- a/api/_lib/llm.js+++ b/api/_lib/llm.js@@ -98,6 +98,14 @@ const ANTHROPIC_MODEL = 'claude-haiku-4-5-20251001';// Paid last-resort tail (see policy above). Mini keeps the backstop cheap; the// repo-wide OpenAI default (api/_lib/chat-models.js) uses the same model.const OPENAI_MODEL = 'gpt-5.4-nano';+// xAI Grok, OpenAI-compatible (api.x.ai). Paid, so it rides in the paid tail+// when the server GROK_API_KEY is set; a caller-supplied BYOK `grokKey` leads+// the chain instead (the caller's explicit model choice on their own billing).+// The budget 4.1-fast tier keeps the server backstop cheap; BYOK callers get+// the flagship via `grokModel`.+const GROK_URL = 'https://api.x.ai/v1/chat/completions';+const GROK_MODEL = 'grok-4.1-fast';+const GROK_BYOK_MODEL = 'grok-4.5';// Per-user daily LLM spend cap, in micro-USD. Callers on the host's paid keys// (ANTHROPIC_API_KEY / OPENAI_API_KEY) are metered; BYOK callers and free-tier@@ -114,10 +122,10 @@ function dailyCapMicroUsd() {// doesn't apply. Returns { exceeded: true, spentMicroUsd, capMicroUsd } when// blocked, or { exceeded: false } when allowed. Never throws — fails open so a// DB hiccup never silently denies a user.-export async function checkUserLlmSpendCap(userId, { anthropicKey } = {}) {+export async function checkUserLlmSpendCap(userId, { anthropicKey, grokKey } = {}) {if (!userId) return { exceeded: false };- if (anthropicKey) return { exceeded: false }; // BYOK — not our billing- if (!env.ANTHROPIC_API_KEY && !env.OPENAI_API_KEY) return { exceeded: false }; // no paid keys at all+ if (anthropicKey || grokKey) return { exceeded: false }; // BYOK — not our billing+ if (!env.ANTHROPIC_API_KEY && !env.OPENAI_API_KEY && !env.GROK_API_KEY) return { exceeded: false }; // no paid keys at allconst cap = dailyCapMicroUsd();try {const [row] = await sql`@@ -273,7 +281,7 @@ function openaiCompatProvider({ name, key = null, url, model, extraHeaders = {},// free provider: the prod paid keys are routinely invalid or out of quota, so// platform spend never leads and nothing depends on it — but when a key does// work, a request that exhausted the free tier still succeeds.-export function providerChain({ anthropicKey, anthropicModel, preferNvidia = false, nvidiaModel = null } = {}) {+export function providerChain({ anthropicKey, anthropicModel, grokKey = null, grokModel = null, preferNvidia = false, nvidiaModel = null } = {}) {const chain = [];// Opt-in: lead with the NVIDIA NIM lane on a chosen Nemotron model. Used by// features that want the NVIDIA-native model to actually produce the result@@ -294,6 +302,17 @@ export function providerChain({ anthropicKey, anthropicModel, preferNvidia = fal}));}if (anthropicKey) chain.push(anthropicProvider(anthropicKey, anthropicModel));+ // BYOK Grok leads for the same reason a BYOK Anthropic key does: the caller+ // chose the model and pays for it. Flagship by default; still degrades to+ // the free chain below when x.ai errors.+ if (grokKey) {+ chain.push(openaiCompatProvider({+ name: 'grok',+ key: grokKey,+ url: GROK_URL,+ model: grokModel || GROK_BYOK_MODEL,+ }));+ }// VERTEX_CLAUDE_PRIMARY: real Claude on GCP credits leads the chain, before// the free lanes — the platform's default brain becomes Vertex Claude. It// still sits behind a caller BYOK key (the caller's explicit billing choice)@@ -421,6 +440,16 @@ export function providerChain({ anthropicKey, anthropicModel, preferNvidia = falmodel: OPENAI_MODEL,}));}+ // Server Grok is a paid backstop like OpenAI above; skipped when a BYOK+ // grokKey already leads (the caller chose their own xAI billing).+ if (!grokKey && env.GROK_API_KEY) {+ chain.push(openaiCompatProvider({+ name: 'grok',+ key: env.GROK_API_KEY,+ url: GROK_URL,+ model: grokModel || GROK_MODEL,+ }));+ }return chain;}@@ -450,14 +479,14 @@ export function llmConfigured(opts = {}) {// { userId, agentId, avatarId, clientId, apiKeyId, tool } — are all optional;// pass whatever the call site knows. Recording is fire-and-forget (see// recordEvent), so it never delays or fails the completion.-export async function llmComplete({ system, user, maxTokens = 1024, anthropicKey = null, anthropicModel = null, preferNvidia = false, nvidiaModel = null, timeoutMs = 30_000, track = null }) {- const chain = providerChain({ anthropicKey, anthropicModel, preferNvidia, nvidiaModel });+export async function llmComplete({ system, user, maxTokens = 1024, anthropicKey = null, anthropicModel = null, grokKey = null, grokModel = null, preferNvidia = false, nvidiaModel = null, timeoutMs = 30_000, track = null }) {+ const chain = providerChain({ anthropicKey, anthropicModel, grokKey, grokModel, preferNvidia, nvidiaModel });if (!chain.length) throw new LlmUnavailableError();// Per-user daily spend cap on platform-paid keys. Only runs when a userId is// known and there are paid keys configured — free-only installs skip the check.if (track?.userId) {- const cap = await checkUserLlmSpendCap(track.userId, { anthropicKey });+ const cap = await checkUserLlmSpendCap(track.userId, { anthropicKey, grokKey });if (cap.exceeded) {const usd = (cap.capMicroUsd / 1_000_000).toFixed(2);throw Object.assign(diff --git a/api/_lib/provider-keys.js b/api/_lib/provider-keys.jsindex 765707739..373276bf0 100644--- a/api/_lib/provider-keys.js+++ b/api/_lib/provider-keys.js@@ -53,6 +53,7 @@ export async function decryptProviderKey(ciphertext) {export const BYOK_PROVIDERS = {anthropic: { label: 'Anthropic', prefix: 'sk-ant-', hint: 'console.anthropic.com/settings/keys' },openai: { label: 'OpenAI', prefix: 'sk-', hint: 'platform.openai.com/api-keys' },+ grok: { label: 'Grok (xAI)', prefix: 'xai-', hint: 'console.x.ai' },meshy: { label: 'Meshy AI', prefix: 'msy_', hint: 'www.meshy.ai/settings/api' },tripo: { label: 'Tripo AI', prefix: 'tsk_', hint: 'platform.tripo3d.ai/api-keys' },rodin: { label: 'Rodin (Hyper3D)', prefix: '', hint: 'developer.hyper3d.ai' },diff --git a/api/brain/chat.js b/api/brain/chat.jsindex 989d7f9a3..6d4d902f6 100644--- a/api/brain/chat.js+++ b/api/brain/chat.js@@ -215,6 +215,42 @@ const PROVIDERS = {native: () => (env.OPENAI_API_KEY ? createOpenAI({ apiKey: env.OPENAI_API_KEY }).chat('o3-pro') : null),openrouterModel: 'openai/o3-pro',},+ 'grok-4.5': {+ label: 'Grok 4.5',+ network: 'xAI',+ tier: 'flagship',+ maxOutput: 16384,+ description: 'xAI flagship. Frontier reasoning with real-time X knowledge.',+ native: () =>+ env.GROK_API_KEY+ ? createOpenAI({ apiKey: env.GROK_API_KEY, baseURL: 'https://api.x.ai/v1' }).chat('grok-4.5')+ : null,+ openrouterModel: 'x-ai/grok-4.5',+ },+ 'grok-4.3': {+ label: 'Grok 4.3',+ network: 'xAI',+ tier: 'balanced',+ maxOutput: 16384,+ description: 'Long-context Grok (1M tokens) at a lower price than 4.5.',+ native: () =>+ env.GROK_API_KEY+ ? createOpenAI({ apiKey: env.GROK_API_KEY, baseURL: 'https://api.x.ai/v1' }).chat('grok-4.3')+ : null,+ openrouterModel: 'x-ai/grok-4.3',+ },+ 'grok-4.1-fast': {+ label: 'Grok 4.1 Fast',+ network: 'xAI',+ tier: 'fast',+ maxOutput: 8192,+ description: 'Budget Grok with a 2M-token context. Fast, cheap workhorse.',+ native: () =>+ env.GROK_API_KEY+ ? createOpenAI({ apiKey: env.GROK_API_KEY, baseURL: 'https://api.x.ai/v1' }).chat('grok-4.1-fast')+ : null,+ openrouterModel: 'x-ai/grok-4.1-fast',+ },'groq-llama': {label: 'Llama 3.3 70B',network: 'Groq',diff --git a/api/chat.js b/api/chat.jsindex dfd2c4c82..1092df11b 100644--- a/api/chat.js+++ b/api/chat.js@@ -119,6 +119,15 @@ const PROVIDERS = {url: 'https://api.openai.com/v1/chat/completions',style: 'openai',},+ // xAI Grok (api.x.ai): paid, OpenAI-compatible. Reached via an explicit+ // provider/model request or a stored BYOK key (Settings > AI Provider Keys);+ // the server GROK_API_KEY, when set, serves it platform-side too.+ grok: {+ envKey: 'GROK_API_KEY',+ defaultModel: PROVIDER_MODEL_DEFAULTS.grok,+ url: 'https://api.x.ai/v1/chat/completions',+ style: 'openai',+ },// IBM watsonx.ai (Granite). URL + headers are derived in makeRoute from the// shared watsonx client (region host, version param, IAM bearer token), so// no static `url` here. Requires WATSONX_API_KEY + a project/space id.@@ -168,7 +177,7 @@ const chatBody = z.object({persona_override: z.string().trim().min(1).max(16000).optional(),agentId: z.string().uuid().optional(),provider: z- .enum(['anthropic', 'openrouter', 'groq', 'nvidia', 'openai', 'watsonx', 'orchestrate'])+ .enum(['anthropic', 'openrouter', 'groq', 'nvidia', 'openai', 'grok', 'watsonx', 'orchestrate']).optional(),model: z.string().min(1).max(120).optional(),history: z@@ -1079,6 +1088,7 @@ const FALLBACK_SIBLINGS = {nvidia: ['meta/llama-3.3-70b-instruct'],anthropic: ['claude-sonnet-4-6', 'claude-haiku-4-5-20251001'],openai: ['gpt-5.4-nano'],+ grok: ['grok-4.5', 'grok-4.1-fast'],};// A model is eligible for an *auto-built* fallback slot only when it can servediff --git a/api/llm/anthropic.js b/api/llm/anthropic.jsindex 4f8f9c136..1c3a8b2e2 100644--- a/api/llm/anthropic.js+++ b/api/llm/anthropic.js@@ -93,6 +93,12 @@ const MODELS = {provider: 'nvidia',envKey: 'NVIDIA_API_KEY',},++ // xAI Grok (paid, host's key). OpenAI-compatible and tool-call capable, so+ // it shares the 'openai' branch. Selectable only; never a free fallback.+ 'grok-4.5': { kind: 'openai', provider: 'grok', envKey: 'GROK_API_KEY' },+ 'grok-4.3': { kind: 'openai', provider: 'grok', envKey: 'GROK_API_KEY' },+ 'grok-4.1-fast': { kind: 'openai', provider: 'grok', envKey: 'GROK_API_KEY' },};const UPSTREAM_URL = {@@ -100,6 +106,7 @@ const UPSTREAM_URL = {openrouter: 'https://openrouter.ai/api/v1/chat/completions',groq: 'https://api.groq.com/openai/v1/chat/completions',nvidia: 'https://integrate.api.nvidia.com/v1/chat/completions',+ grok: 'https://api.x.ai/v1/chat/completions',};const FIRST_PARTY = ['three.ws', 'localhost'];diff --git a/api/user/provider-keys.js b/api/user/provider-keys.jsindex 2a2b6d17d..689209b37 100644--- a/api/user/provider-keys.js+++ b/api/user/provider-keys.js@@ -1,6 +1,6 @@// GET /api/user/provider-keys — returns which keys are set (never returns values)// PATCH /api/user/provider-keys — set or clear individual provider keys-// body: { anthropic?, openai?, meshy?, tripo?, rodin?, stability?, replicate? } — each string | null+// body: { anthropic?, openai?, grok?, meshy?, tripo?, rodin?, stability?, replicate? } — each string | null// null = delete that key; string = store encryptedimport { sql } from '../_lib/db.js';@@ -14,6 +14,7 @@ import { parse } from '../_lib/validate.js';const patchSchema = z.object({anthropic: z.string().min(1).max(512).nullable().optional(),openai: z.string().min(1).max(512).nullable().optional(),+ grok: z.string().min(1).max(512).nullable().optional(),meshy: z.string().min(1).max(512).nullable().optional(),tripo: z.string().min(1).max(512).nullable().optional(),rodin: z.string().min(1).max(512).nullable().optional(),diff --git a/api/v1/_providers.js b/api/v1/_providers.jsindex 790423105..bd7d9e77f 100644--- a/api/v1/_providers.js+++ b/api/v1/_providers.js@@ -120,7 +120,7 @@ function slimDexProfileList(data, cap = 30) {// ── Solana JSON-RPC helpers ──────────────────────────────────────────────────// Solana RPC URL — same env resolution the rest of the platform uses-// (api/_lib/env.js SOLANA_RPC_URL: configured Helius/QuickNode/Triton URL, or+// (api/_lib/env.js SOLANA_RPC_URL: configured Helius/Quicknode/Triton URL, or// the public mainnet endpoint). Computed once at module load per the registry// contract — a deploy that sets SOLANA_RPC_URL later needs a redeploy to pick// it up, same as every other provider `base`.@@ -737,6 +737,42 @@ export const PROVIDERS = [},],},+ {+ id: 'grok',+ name: 'Grok (xAI)',+ category: 'ai-inference',+ base: 'https://api.x.ai/v1',+ requiresKey: true,+ envVar: 'GROK_API_KEY',+ byokHeader: 'x-provider-key',+ applyKey: (headers, _url, key) => {+ if (key) headers['authorization'] = `Bearer ${key}`;+ },+ endpoints: [+ {+ id: 'chat',+ method: 'POST',+ path: '/chat/completions',+ body: (b) => {+ if (!b || typeof b !== 'object' || !Array.isArray(b.messages)) {+ const err = new Error('body must include a "messages" array');+ err.status = 400;+ err.code = 'validation_error';+ throw err;+ }+ return b;+ },+ priceAtomics: '5000',+ scope: 'agents:write',+ summary: 'Chat completions against xAI Grok models (grok-4.5, grok-4.3, grok-4.1-fast; BYOK supported).',+ params: {+ model: 'Grok model id, e.g. "grok-4.5" (required)',+ messages: 'array of {role, content} (required)',+ '…': 'any other OpenAI chat-completions parameter is forwarded',+ },+ },+ ],+ },{id: 'dexscreener',name: 'DexScreener',@@ -831,7 +867,7 @@ export const PROVIDERS = [name: 'Solana RPC',category: 'onchain-data',// Same env resolution every other Solana caller on the platform uses- // (api/_lib/env.js) — a configured Helius/QuickNode/Triton URL, or the+ // (api/_lib/env.js) — a configured Helius/Quicknode/Triton URL, or the// public mainnet endpoint as a working fallback.base: SOLANA_RPC_BASE,requiresKey: false,diff --git a/src/brain.js b/src/brain.jsindex 3c2650ab4..730f5ba0b 100644--- a/src/brain.js+++ b/src/brain.js@@ -23,6 +23,9 @@ const PROVIDERS = [{ key: 'o3', label: 'o3', short: 'o3', network: 'OpenAI', color: '#c0e4ff', ctx: '200K', tier: 'Reasoning' },{ key: 'o3-pro', label: 'o3-pro', short: 'o3-pro', network: 'OpenAI', color: '#cce9ff', ctx: '200K', tier: 'Reasoning' },{ key: 'o3-mini', label: 'o3-mini', short: 'o3-mini', network: 'OpenAI', color: '#5cb0f4', ctx: '128K', tier: 'Reasoning' },+ { key: 'grok-4.5', label: 'Grok 4.5', short: 'Grok 4.5', network: 'xAI', color: '#e8e8e8', ctx: '500K', tier: 'Flagship' },+ { key: 'grok-4.3', label: 'Grok 4.3', short: 'Grok 4.3', network: 'xAI', color: '#d0d0d0', ctx: '1M', tier: 'Balanced' },+ { key: 'grok-4.1-fast', label: 'Grok 4.1 Fast', short: 'Grok Fast', network: 'xAI', color: '#bcbcbc', ctx: '2M', tier: 'Fast' },{ key: 'groq-llama', label: 'Llama 3.3 70B', short: 'Llama 3.3', network: 'Groq', color: '#ff9a3c', ctx: '128K', tier: 'Fast' },{ key: 'qwen-plus', label: 'Qwen Plus', short: 'Qwen+', network: 'DashScope', color: '#69db7c', ctx: '131K', tier: 'Balanced' },{ key: 'modelscope-qwen', label: 'Qwen3-Coder 480B', short: 'Qwen3-Code', network: 'ModelScope', color: '#40c057', ctx: '32K', tier: 'Flagship' },