API / JAVASCRIPT

Muse Wonder JavaScript API: A Server-Side Node.js Example

Build a small server-side JavaScript integration before adding Muse Wonder to a larger application. This example uses the Muse Wonder Network endpoint and purchased website credits. It requires Node.js 22 or later and native fetch, so there is no SDK dependency to install.

Quick answer

Create a website API key, set MUSEWONDER_API_KEY in your server environment and POST text messages to /api/v1/chat/completions with model meta/muse-wonder. Read choices[0].message.content for a non-streamed answer. A provider key cannot replace the website key in this example.

Prepare the environment and balance

Sign in with Google or GitHub, activate your 100 sign-up credits with a verified email or buy website credits, then create a website API key. Trial credits expire 7 days after registration and are shared with chat. Use the complete value shown at creation, beginning mw_live_. Store it in your server environment rather than a browser bundle or a NEXT_PUBLIC_ variable. For local development only, set MUSEWONDER_BASE_URL to http://localhost:3000 while this app is running. Otherwise the script defaults to the public website. Creating a key does not grant generation credits.

Continue your evaluation: Create a website API key · Estimate website credit usage

Run the complete Node.js example

Save the following file as muse-chat.mjs, set the environment variables using your shell or deployment secret manager, and run node muse-chat.mjs. The script makes one potentially billable request, validates the HTTP result and requires a visible answer. The client timeout is 120 seconds; a timeout does not establish that a request was free.

JAVASCRIPT / NODE.JS
// Save as muse-chat.mjs. Requires Node.js 22+; no package installation.
const base = process.env.MUSEWONDER_BASE_URL || 'https://musewonder.network';
const key = process.env.MUSEWONDER_API_KEY;
if (!key) throw new Error('Set MUSEWONDER_API_KEY on your server.');

const response = await fetch(base.replace(/\/$/, '') + '/api/v1/chat/completions', {
  method: 'POST',
  headers: { Authorization: 'Bearer ' + key, 'Content-Type': 'application/json' },
  signal: AbortSignal.timeout(120000),
  body: JSON.stringify({
    model: 'meta/muse-wonder',
    messages: [{ role: 'user', content: 'Explain a safe API rollout in three steps.' }],
    max_tokens: 1024,
    reasoning: { effort: 'medium' },
    stream: false
  })
});
const data = await response.json().catch(() => null);
if (!response.ok || data?.error) {
  throw new Error('HTTP ' + response.status + ': ' + (data?.error?.message || 'Request failed'));
}
const answer = data?.choices?.[0]?.message?.content;
if (typeof answer !== 'string' || !answer.trim()) throw new Error('No visible answer returned.');
console.log(answer);
console.log('Charged credits:', data.usage?.credits_charged ?? 'pending review');

Read the response and settled usage

A normal non-streamed reply contains a choices array with an assistant message. The usage object can include prompt_tokens, completion_tokens, credits_charged and billing_status. A missing settled charge is not a zero charge: check account usage if billing needs review. Do not pass the complete upstream response to logs if it contains confidential generated text.

ILLUSTRATIVE RESPONSE / NOT A MEASURED GENERATION
{"choices":[{"message":{"role":"assistant","content":"Example reply"},"finish_reason":"stop"}],"usage":{"prompt_tokens":100,"completion_tokens":80,"credits_charged":2,"billing_status":"settled"}}

Keep the website request within its contract

This endpoint accepts text messages with system, user and assistant roles, with a user message last. Use 1–40 messages, no more than 16,000 characters per message and 32,000 characters across the conversation. max_tokens accepts integers from 256 to 16,384. These are website limits, not the model’s advertised context capacity. Tool execution, file uploads and other model endpoints are not exposed here.

Continue your evaluation: Website API contract · Diagnose validation errors

Move from a script to an application

Put the provider call behind your own authenticated server route. Authorize the caller before spending your website balance, cap message sizes and output, and decide how your application stores conversation history. For a follow-up, resend the allowed text messages and account for the growing context. Review streaming separately rather than attempting response.json() on an SSE body. The example is checked with mocked protocol responses, not a live paid inference or a production load test.

Continue your evaluation: Read streamed responses · Production integration checklist

YOUR NEXT STEP

Connect your application.

Create a website key and fund the shared account balance. Start with the API contract, then test one small server-side request.

VERIFY THE DETAILS

Sources & update notes.

Specifications and availability can change. Follow the source for the exact model and provider. Model capabilities are separate from the features offered by this website.

Related reading.