Install
@meshrouter/sdk.
First request
https://api.meshrouter.app/v1. Pass baseUrl to override.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Official @meshrouter/sdk client for Node.js and the browser.
npm install @meshrouter/sdk
# or
pnpm add @meshrouter/sdk
# or
yarn add @meshrouter/sdk
@meshrouter/sdk.
import { Mesh } from '@meshrouter/sdk';
const mesh = new Mesh({ apiKey: process.env.MESH_API_KEY! });
const reply = await mesh.ai.chat({
model: 'auto',
messages: [{ role: 'user', content: 'route this privately' }],
maxOutputTokens: 200,
});
console.log(reply.content);
console.log('receipt:', reply.receiptId, '$' + reply.actualCustomerChargeUsd);
https://api.meshrouter.app/v1. Pass baseUrl to override.
for await (const chunk of mesh.ai.stream({
model: 'mesh/claude-sonnet-4.5',
messages: [{ role: 'user', content: 'stream this' }],
maxOutputTokens: 500,
})) {
if (chunk.delta) process.stdout.write(chunk.delta);
}
const quote = await mesh.ai.quote({
model: 'mesh/claude-opus-4.6',
messages: [{ role: 'user', content: 'summarize this 10k-token doc...' }],
maxOutputTokens: 1000,
});
console.log('max charge:', quote.estimatedMaxCharge);
console.log('expires at:', quote.expiresAt);
const models = await mesh.models.list();
for (const m of models) {
console.log(m.alias, m.provider, m.inputUsdPerMillion + '/' + m.outputUsdPerMillion);
}
import {
MeshAuthError,
MeshInsufficientBalanceError,
MeshValidationError,
MeshDuplicateRequestError,
} from '@meshrouter/sdk';
try {
await mesh.ai.chat({
/* … */
});
} catch (err) {
if (err instanceof MeshInsufficientBalanceError) {
console.error(`Top up ${err.required} USD; have ${err.available}.`);
} else if (err instanceof MeshAuthError) {
console.error('Bad API key.');
} else if (err instanceof MeshValidationError) {
console.error('Bad request:', err.code, err.message);
}
}