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.

fix(chat): fund Gemini's reasoning budget so replies stop stopping mid-sentence

nirholas433f06ea399e
diff --git a/api/chat.js b/api/chat.js
index 513f4e08f..dd0a56e92 100644
--- a/api/chat.js
+++ b/api/chat.js
@@ -65,6 +65,7 @@ import {
vertexRequestHeaders,
toVertexBody,
} from './_lib/vertex-claude.js';
+import { vertexGeminiBudget } from './_lib/vertex-gemini.js';
import { z } from 'zod';
// Providers anonymous (unauthenticated) callers may use. Groq and OpenRouter
@@ -1356,7 +1357,11 @@ function makeRoute(name, cfg, apiKey, model) {
resolveHeaders: () => vertexRequestHeaders(),
buildPayload: ({ systemPrompt, history, maxTokens, includeTools = true }) => ({
model,
- max_tokens: maxTokens,
+ // Gemini reasons by default and its reasoning tokens are billed against
+ // max_tokens without being returned, so a plain budget streams a reply
+ // that stops mid-sentence. vertexGeminiBudget caps the reasoning and
+ // funds it on top of the caller's budget (max_tokens + extra_body).
+ ...vertexGeminiBudget(maxTokens),
messages: [{ role: 'system', content: systemPrompt }, ...history],
...(includeTools ? { tools: OPENAI_TOOLS, tool_choice: 'auto' } : {}),
stream: true,