Skip to main content
You need a mesh_live_... API key. Sign in at meshrouter.app to create one, or email us to request access. Prefer a browser? Open MESH chat to talk to any model without an API key.

1. Set your environment

export MESH_API_KEY=mesh_live_...
export OPENAI_BASE_URL=https://api.meshrouter.app/v1
export OPENAI_API_KEY=$MESH_API_KEY

2. Send a request

import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: process.env.OPENAI_BASE_URL,
  apiKey: process.env.OPENAI_API_KEY,
});

const completion = await client.chat.completions.create({
  model: 'auto',
  messages: [{ role: 'user', content: 'Hello MESH' }],
});

console.log(completion.choices[0]?.message?.content);
model: "auto" lets MESH pick a model for you. To pin a specific one, pass its MESH id (e.g. "mesh/claude-sonnet-4.5", "mesh/balanced", "mesh/deepseek-r1"). See Models for the full catalogue and Routing for fallback chains.

3. Read the receipt

Every routed call returns these headers:
HeaderMeaning
x-mesh-upstream-cost-usdWhat the provider charged
x-mesh-margin-usdMESH margin on the call
x-mesh-total-usdTotal drawn from your balance
x-mesh-receipt-idID for lookup via /v1/receipts/:id

What’s next