- From source. You send
main.rs. A host compiles it in a microVM on therust:1.99-buildimage and the version runs the binary onrust:1.99. - As an image. You compile the binary yourself and copy it into an image
on
static:13.
localhost:8780 with no auth, as in the
Quickstart. With auth enabled, add
-H "Authorization: Bearer $TOKEN" to every call.
The Rust runtime
The default prefix is
ghcr.io/galaxy-io/alchemy/runtime, set by the server’s
RUNTIME_IMAGE_PREFIX. Ask the server for the exact image:
cargo build --release --offline. Your files land
in a crate named handler, edition 2024, whose binary is built from
main.rs. Its dependencies are fixed:
A function that needs other crates ships as an image.
The protocol
For each invocation the supervisor starts/app/handler as a new process,
writes the input to stdin and closes it, takes stdout as the output and
streams stderr to the invocation’s log. A non-zero exit, including a panic,
is a crash, reported with the exit status and the last 4 KiB of stderr. A
JSON Schema contract passes one JSON value each way, an Arrow contract one IPC
stream with exactly one record batch. See
Contracts.
Write a handler
The runtime’s JSON Schema starter:main.rs
RecordBatch:
main.rs
examples/embed/rust
is a complete Arrow function that returns the cleaned text, its token count
and a 64-dimension embedding per row. It is a standalone crate on arrow 57,
built as an image below.
The Arrow contract’s schemas are serialized Arrow IPC. Build them as in the
Python guide, which writes arrow.json for
the embed example, or define the fields in the web UI.
Deploy from source
A source version namesrust:1.99 as its image and carries main.rs. When
the version builds, the server compiles it first:
- The least busy host boots
rust:1.99-buildin a microVM of its own, with 2 vCPUs and 2 GiB, or the host’s whole memory budget when that is smaller. - The build image copies your files into the crate and runs
cargo build --release --offline. The compiler’s output is the build log. - The host stores the binary as a layer in the artifacts bucket, and the
version is built from
rust:1.99with that layer at/app/handler.
1
Create the function
mod in main.rs can be sent as more .rs
files next to it. Do not send a Cargo.toml or Cargo.lock: they
replace the crate’s, and a dependency the build image has not compiled
fails the offline build.2
Wait for the build
statusMessage starts with
compile failed: and buildLog holds cargo’s output.Deploy as an image
Build the binary yourself for other crates or build settings. The embed example builds against musl and copies the binary ontostatic:13:
Dockerfile
static:13 has no libc, so the binary must be fully static, which the
Alpine (musl) toolchain gives by default. Build for the hosts’ architecture
and push:
source:
Invoke it
POST the input with the contract’s content type:input.arrows as in the Python guide.
The response carries Alchemy-Invocation-Id and Alchemy-Version. A handler
that panics or exits non-zero answers 500, and one past its timeout 504.
See HTTP invoke.
Next steps
Troubleshooting
Read compile failures, crashes and contract violations.
Runtimes and builds
How a spec becomes a root filesystem and a snapshot.