API Maker

The backend engine for the AI era

Chapters

What you will learn

  • A group of sandboxes for one API: separateSandboxSettings on Bun
  • Where a call ran, with x-am-meta: the group, the runtime, the port
  • A second API in the same group: shared packages and g.shared
  • What a save refuses, with the reason
  • The sandbox count, and x-am-run-in-sandbox for state in memory
  • autoRestart: a new sandbox every minute, every call answered
  • Packages of Sandbox Settings for code on the native process
In the docsCustom API settings : separate sandbox
Transcript1146 words · click a time to play from there

Intro

Here are separate sandboxes. Heavy APIs get their own sandboxes, with their own runtime, packages, and count, and restarts that drop no call. And code on the server machine gets the packages of Sandbox Settings.

Heavy APIs, the usual way

Heavy APIs usually cause trouble. A report holds the sandboxes that every other API waits for. Another runtime needs a second service, built and deployed by hand. A library that leaks memory needs restarts at night, and those restarts drop calls. And code that runs on the machine needs packages installed by hand on each server. With API Maker, a few lines of settings give an API its own sandboxes.

They run on the runtime and version it names. They restart on a timer, without a failed call. And code on the machine finds the packages of Sandbox Settings. In this video: a group of sandboxes for one API, a second API in the same group, what a save refuses, the sandbox count and x-am-run-in-sandbox, restarts that drop no call, and packages on the native process.

A group of its own

Every TypeScript custom API runs in the TypeScript sandboxes. They share one runtime, one list of packages, and one sandbox count. Calm Home adds month end reports. They make statistics over every order, they are heavy, and they run on Bun. So they get their own group, named reports. It has its own sandboxes, with their own runtime and packages, so a long report never makes a cart wait. Open Custom API, the folder reports, and Sales Report.

Click Edit. Under its access type, add separateSandboxSettings. The group is reports, the runtime is Bun, with two sandboxes at most on each server, a new sandbox every hour, and the package simple-statistics, on top of the packages of Sandbox Settings. Click Update. The tree shows the group. Both reports are in the folder. Click Test API on Sales Report. In Header, set x-am-meta to true, and Send. We get the orders of MySQL, in figures made by simple-statistics, on Bun.

And the meta says where the code ran: the group reports, the runtime bun, and the port of its sandbox. The code imports simple-statistics, like any npm package. It reads the totals of the MySQL orders, and adds one to a count kept in g.shared. That is what the runner of a sandbox keeps between calls. The count tells which runner took a call, and the name of its machine tells which sandbox.

The code names no runtime. The group runs it on Bun.

A second API in the group

Here is a second report, Top Products. Click Edit. Under its access type, it names the group, and nothing else. Click Update. Now both reports share the group. They use the same sandboxes and the same packages, and what one leaves in g.shared, the other finds. What if Top Products wants its own count? Under the group, set four sandboxes. Update is refused, with the reason. Sales Report names two, and the APIs of a group share what their sandboxes are made of.

Name it in one of them, or the same in each. Close it. Nothing was saved.

What a save refuses

A save checks every key of the group, and says what to do. It refuses a runtime without a group, because it would change nothing. It refuses a runtime of another language. It refuses a restart under sixty seconds. It refuses a count out of range, a version too old for its runtime, a package that its store does not take, and a Dockerfile with CMD. A mistake fails when you click Update, never in the middle of a call.

Sandbox count and x-am-run-in-sandbox

There are two sandboxes at most. The first call starts one, and the second starts beside it. Here are six calls in a row, and each answer names its sandbox. They take turns, one sandbox, then the other, and each runner counts its own reports. Some code keeps state in memory, like a connection that a process initializer opened, or its own cache. The header x-am-run-in-sandbox, set to one, sends every call to the oldest sandbox of the group.

It is the same sandbox every time, and the count climbs one by one. Top Products, on the same sandbox, finds the count that Sales Report left. One group shares one g.shared. Two means one of the two oldest. Zero means any sandbox.

Restarts which drop no call

Some libraries hold on to memory. autoRestart gives a sandbox a lifetime. Use an hour in production. Here, we use sixty seconds, the minimum, so we can watch. Click Update. A call comes every second. Each sandbox gives up its place after its own sixty seconds. The new one starts first, and the old one finishes what it runs, then goes. It happens one sandbox at a time, so the other keeps answering.

Every call is answered.

Packages on the native process

Product QR runs on the native process, on the server machine, for the lowest delay. Click Test API, and Send. It says: cannot find module qrcode. Until now, native code found only what was installed by hand. Open Operations, then Sandbox Settings. Search npm for qrcode, pick it, click Add, and Save. Open the menu, then API Testing, Custom APIs, and Product QR. In Header, set x-am-meta to true, and Send.

We get the QR code of the label. runOnNativeProcess is true, and there is no port, because there is no sandbox at all. The first time the code runs, the packages are installed on the server machine, in their own folder, with the tool of each language: npm or Bun, pip, Composer, go, cargo, NuGet, and Maven, in the same versions as the images. Every account with the same packages shares that folder, and its runner.

And code of a group runs on the runtime of its group, with the packages of its group.

Good to know

Good to know. The hooks of the versions of an API run in the sandboxes of its group, in the same request. Accounts with the same settings share one image, built when the API is saved. The restart of Sandbox Settings is for the other sandboxes. A group has its own restart, or none. And the sandbox for debugging never restarts, because you are looking at it. What a group is made of is said once, and checked on every save.

So code that an AI assistant writes in another API of the group cannot quietly change the runtime of the reports. The save says why, in words, and what to do.

Recap

To sum up. A few lines give an API its own sandboxes. The APIs of a group share its sandboxes, its packages, and g.shared. A save refuses what cannot be made, with the reason. Calls take turns, or go to the oldest sandbox with x-am-run-in-sandbox. Restarts on a timer drop no call. And native code gets the packages of Sandbox Settings. Next: deploying a new version of API Maker. API Maker.

Build faster, spend smarter, deliver better.