docs
SupportConsole

Build a quoting page

An upload form on your site that shows the customer a price, a print time and the filament weight while they wait.

Customers who can see a price don't have to email you for one. This guide puts an upload form on your site. The customer drops in a model, your server sends it to Superslice, and the page shows the quote when the slice finishes.

Why the server sits in the middle

The browser could post to Superslice directly, but then your API key would be in the page for anyone to copy. Your server holds the key, the settings and the rates. The browser only sends a file to you and gets a quote back. See Security.

Before you start

  • A server that can read uploads. The route below is a standard Request handler, so it runs as a Next.js route handler, in Hono or in a Cloudflare Worker.
  • An API key with slices:write and slices:read, in SUPERSLICE_API_KEY.
  • Your settings and prices, set up as in Quote a customer's upload, steps 1 and 2.

Add the upload form

html
<form id="quote" enctype="multipart/form-data">
  <label for="model">Your model (.stl or .3mf, up to 95 MB)</label>
  <input id="model" name="file" type="file" accept=".stl,.3mf" required />
  <button type="submit">Get a price</button>
</form>
<p id="result" role="status"></p>

Slice it on your server

The route forwards the file with your settings, then checks the slice every 2 seconds until it finishes. A customer staring at a spinner wants polling here, not a callback.

js
// app/api/quote/route.js in Next.js. The same handler works in Hono or a Worker.
const API = 'https://api.superslice.co/v1';
const headers = { Authorization: `Bearer ${process.env.SUPERSLICE_API_KEY}` };
const SETTINGS = {
  slicer: 'bambu-studio',
  printer: 'Bambu Lab A1 0.4 nozzle',
  process: '0.20mm Standard @BBL A1',
  filament: 'Bambu PLA Basic @BBL A1',
  plate_type: 'Textured PEI Plate',
};

export async function POST(request) {
  const file = (await request.formData()).get('file');
  if (!(file instanceof File)) return Response.json({ error: 'Choose a .stl or .3mf file.' }, { status: 400 });

  const body = new FormData();
  body.append('file', file, file.name);
  body.append('request', JSON.stringify(SETTINGS));
  const res = await fetch(`${API}/slices`, { method: 'POST', headers, body });
  let slice = await res.json();
  if (!res.ok) return Response.json({ error: slice.title, code: slice.code }, { status: res.status });

  while (slice.status !== 'succeeded' && slice.status !== 'failed') {
    await new Promise((r) => setTimeout(r, 2000));
    const check = await fetch(`${API}/slices/${slice.id}`, { headers });
    if (!check.ok) return Response.json({ error: 'Try again in a moment.' }, { status: 502 });
    slice = await check.json();
  }
  if (slice.status === 'failed') return Response.json({ error: slice.error.message, code: slice.error.code }, { status: 422 });
  return Response.json({ price: slice.price, print_time_s: slice.result.print_time_s, filament_g: slice.result.filament_g });
}

This waits inside the request, which is the simplest thing that works. If your host cuts requests off before a slice finishes, return the slice id at once and let the page poll your server instead.

The customer's file and your settings make one slice. If two customers upload the same file, the second gets the stored result at once, and it doesn't count toward your plan.

Show the quote

js
const form = document.querySelector('#quote');
const out = document.querySelector('#result');

form.addEventListener('submit', async (event) => {
  event.preventDefault();
  out.textContent = 'Slicing your model…';
  const res = await fetch('/api/quote', { method: 'POST', body: new FormData(form) });
  const quote = await res.json();
  if (!res.ok) return (out.textContent = quote.error);

  const money = new Intl.NumberFormat(undefined, { style: 'currency', currency: quote.price.currency });
  const total = quote.price.total_minor / 10 ** money.resolvedOptions().maximumFractionDigits;
  const mins = Math.round(quote.print_time_s / 60);
  const time = mins < 60 ? `${mins} min` : `${Math.floor(mins / 60)} h ${mins % 60} min`;
  out.textContent = `${money.format(total)} · prints in ${time} · ${quote.filament_g.toFixed(1)} g of filament`;
});

For the example bracket, that reads $5.00 · prints in 20 min · 7.9 g of filament.

Let them pick a material

One price for every material is rarely right. Give each filament its own rate with a pricing variation, then add a material dropdown to the form and send the chosen filament name in place of the fixed one. Take the names from GET /v1/engines/{release}/filaments, and check the value from the form against that list on your server before you use it.

If it fails

The route passes our code through, so the page can say something useful:

CodeShow the customer
model_too_largeThat file is over 95 MB. Try a smaller export.
model_unreadableWe couldn't read that file. Export it again as STL or 3MF.
model_out_of_bedThat model is bigger than our printer. Scale it down or contact us.
unsupported_featureWe can quote single-colour models only.
slice_limit_reachedQuotes are paused. Contact us for a price.

The last one is for you, not the customer: upgrade or buy a top-up, as Limits explains. For anything else, show a general message and log the code. All of them are on Errors.