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
fix(llm): accept the system turns Claude Code sends inside messages, so the CLI's agentic loop runs on the free proxy chain
nirholasd3074c1c8627
diff --git a/api/llm/anthropic.js b/api/llm/anthropic.jsindex d13e5427b..80fd2a6f8 100644--- a/api/llm/anthropic.js+++ b/api/llm/anthropic.js@@ -450,7 +450,10 @@ const bodySchema = z.object({messages: z.array(z.object({- role: z.enum(['user', 'assistant']),+ // `system` turns are how the Claude Code CLI delivers its environment+ // block mid-conversation; the Messages API accepts them, so they are+ // passed through to Anthropic lanes and hoisted for OpenAI-shape ones.+ role: z.enum(['user', 'assistant', 'system']),content: messageContentSchema,}),)@@ -1055,10 +1058,18 @@ export function toolResultText(content) {export function anthropicBodyToOpenAI(body, { provider } = {}) {const messages = [];- const system = flattenSystem(body.system);+ // OpenAI-compatible servers disagree about a system message that is not the+ // first one (several chat templates refuse it outright), so every in-thread+ // `system` turn is folded into the leading system prompt, in order.+ const systemParts = [flattenSystem(body.system)];+ for (const m of body.messages) {+ if (m.role === 'system') systemParts.push(typeof m.content === 'string' ? m.content : flattenSystem(m.content.filter((b) => b?.type === 'text')));+ }+ const system = systemParts.filter(Boolean).join('\n\n');if (system) messages.push({ role: 'system', content: system });for (const m of body.messages) {+ if (m.role === 'system') continue;if (typeof m.content === 'string') {messages.push({ role: m.role, content: m.content });continue;diff --git a/docs/api-reference.md b/docs/api-reference.mdindex f4834e988..ba1f9d56e 100644--- a/docs/api-reference.md+++ b/docs/api-reference.md@@ -1186,7 +1186,7 @@ ANTHROPIC_BASE_URL=https://three.ws/api/llm/anthropic/agents/<agent_id>ANTHROPIC_AUTH_TOKEN=sk_live_...```-That reaches `POST /api/llm/anthropic/agents/<agent_id>/v1/messages`, which is this same proxy with the same auth, policy, ceilings and model rules. `system` may be a string or an array of text blocks (at most 64,000 characters in total), and a `max_tokens` above 16,000 is clamped to 16,000 rather than rejected. Only meter against an agent you own: the per-agent ceilings and budget below are that agent's.+That reaches `POST /api/llm/anthropic/agents/<agent_id>/v1/messages`, which is this same proxy with the same auth, policy, ceilings and model rules. `system` may be a string or an array of text blocks (at most 64,000 characters in total), `messages` may carry `system` turns between user and assistant turns (the free OpenAI-compatible models receive them folded into the system prompt), and a `max_tokens` above 16,000 is clamped to 16,000 rather than rejected. This is enough for the Claude Code CLI to run its full agentic loop, tool calls included, on the free model chain. Only meter against an agent you own: the per-agent ceilings and budget below are that agent's.**Who may call it.** This lane is billed to the platform's own provider keys, so it is scoped to the browser embed it exists for:diff --git a/tests/api/llm-anthropic.test.js b/tests/api/llm-anthropic.test.jsindex 76b951f88..377b7789a 100644--- a/tests/api/llm-anthropic.test.js+++ b/tests/api/llm-anthropic.test.js@@ -1153,6 +1153,34 @@ describe('/api/llm/anthropic: Anthropic SDK clients', () => {expect(fetchState.calls).toHaveLength(0);});+ it('accepts an in-thread system turn and folds it into the system prompt for OpenAI-shape lanes', async () => {+ const { status } = await invokeSdk({+ model: 'google/gemma-4-31b-it:free',+ system: [{ type: 'text', text: 'base prompt' }],+ messages: [+ { role: 'user', content: [{ type: 'text', text: 'hi' }] },+ { role: 'system', content: [{ type: 'text', text: '# Environment' }] },+ ],+ });+ expect(status).toBe(200);+ const sent = JSON.parse(fetchState.calls[0].init.body);+ expect(sent.messages).toEqual([+ { role: 'system', content: 'base prompt\n\n# Environment' },+ { role: 'user', content: 'hi' },+ ]);+ });++ it('passes an in-thread system turn to an Anthropic lane unchanged', async () => {+ fetchState.response = () => upstreamOk({ ok: true, usage: { input_tokens: 1, output_tokens: 1 } });+ const messages = [+ { role: 'user', content: 'hi' },+ { role: 'system', content: [{ type: 'text', text: '# Environment' }] },+ ];+ const { status } = await invokeSdk({ max_tokens: 10, messages });+ expect(status).toBe(200);+ expect(JSON.parse(fetchState.calls[0].init.body).messages).toEqual(messages);+ });+it('clamps an oversized max_tokens instead of rejecting the request', async () => {const { status } = await invokeSdk({ ...VALID_BODY, model: 'google/gemma-4-31b-it:free', max_tokens: 32_000 });expect(status).toBe(200);