Models
Publish a model
Upload a compiled model and register it with its window and bond.
Publishing puts a compiled model on the network: one register_model transaction records its roots, its window and its bond for good, and four uploads put its files in the store where browsers and nodes fetch them. laplace model publish does both. This page covers the command, what the registration records, the upload and its checks, what the publisher pays, and what happens next.
Before publishing
- A compiled model folder holding
manifest.json,program.bin,weights.binand the tokenizer, from Compile a model. - A key with SOL for one transaction and the rent of one account. The CLI reads it from its sealed key file; CLI covers
laplace key newand--key. - A key the program lets register. While
registration_openon the program'sConfigisfalse, only the program's admin registers models; once the admin sets it totrue, any key does. Who may register shows how to read it. - The network's RPC and API addresses, passed as
--rpcand--apior set asLAPLACE_RPCandLAPLACE_API. They are listed on Addresses. - A window and a bond. Choosing a bond and a window covers how to set them.
Publish
Run the command
Shell laplace model publish ./out/market --window 900 --bond 2This registers the model with a window of 900 seconds and a bond of 2 SOL per answer. The CLI asks for the key file's password, or reads it from
LAPLACE_PASSWORD.It registers the model
The CLI reads
manifest.jsonand looks up theModelaccount for its slug. When the account does not exist it sendsregister_model, signed by the key: the admin's key while registration is closed. When it exists the CLI skips this step and only uploads.It uploads the files
Four requests to
POST /v1/files, in this order: the manifest,program.bin,weights.bin, the tokenizer. The store checks each against the chain before keeping it.Read what it printed
One JSON object with three fields:
slug,model(the address of theModelaccount) andsignature(theregister_modeltransaction, ornullwhen the account already existed).
Arguments
dirpathrequired- The compiled model folder.
--windowseconds- The model's window. An integer number of seconds. Left out, the CLI sends
600. --bondSOL- The model's bond per answer, in SOL, decimals allowed. It is converted to lamports and rounded. Left out, the CLI sends
1. --rpcurl- The cluster's RPC address. Also
LAPLACE_RPC. --apiurl- The network's API address, whose store takes the files. Also
LAPLACE_API. --keypath- The sealed key file of the publisher. Also
LAPLACE_KEY. The default is.laplace/key.jsonin the home folder.
Who may register
Config.registration_open decides who signs register_model. It is false from the moment the program is set up, and the admin changes it with set_config.
registration_open | Who registers |
|---|---|
false | The admin, the key in Config.admin. Any other key is refused with Unauthorized (6000). |
true | Any key. |
import { Connection } from '@solana/web3.js'
import { decode, pda } from '@laplace/sdk'
const connection = new Connection(process.env.LAPLACE_RPC!, 'confirmed')
const info = await connection.getAccountInfo(pda.config(), 'confirmed')
const config = decode.config(info!.data)
config.registrationOpen // false: only config.admin registers
config.adminWhat register_model records
The instruction creates the Model account at seeds ["model", slug]. The publisher signs and pays for it.
| Field | From | Meaning |
|---|---|---|
slug | The manifest | The model's name on the network and the seed of its address. |
publisher | The signer | The key that registered it. |
arch | The manifest | 0 for the judge, 1 for the market model. |
weights_root, program_root, init_root | The manifest's roots | What every proof in a dispute is checked against. |
step_count, state_pages, chunk_count | The manifest | The size of the run, the state and the weights. |
input_max, output_len | The manifest | The most input tokens a request may carry and the exact length of an answer. |
window_secs | --window | The seconds after an answer during which anyone may challenge it. |
bond_lamports | --bond | The lamports locked behind each answer, and the bond a challenger posts. |
files_hash | The SHA-256 of manifest.json | What the store checks an uploaded manifest against. |
registered_at | The chain's clock | Clock.unix_timestamp when the instruction ran. |
The instruction fails with Unauthorized (6000) when registration is closed and the signer is not the admin, and with InvalidModel (6002) when the slug is empty, longer than 24 bytes or holds a character other than a lowercase letter, a digit or -, when a count, the window or the bond is zero, or when input_max or output_len is outside 1 to 64.
A slug is registered once. The address is derived from the slug alone, so a second register_model for a slug that is taken fails, whoever sends it.
The upload
POST /v1/files takes one file per request: the raw bytes as the body, and two headers.
| Header | Value |
|---|---|
X-Model | The model's slug. |
X-File | manifest, program, weights or tokenizer. |
Content-Type | application/octet-stream |
curl -X POST "$LAPLACE_API/v1/files" \
-H "Content-Type: application/octet-stream" \
-H "X-Model: market" -H "X-File: manifest" \
--data-binary @out/market/manifest.jsonThe response is { "hash": "<sha256 of the file, hex>", "bytes": <its size> }. The store keeps a file under its SHA-256 and writes it once, so uploading the same file again returns the same answer.
The store reads the Model account from the chain on every upload and keeps a file only when the chain vouches for it:
| File | Kept when |
|---|---|
manifest | Its SHA-256 equals the model's files_hash, and the three roots it names equal the model's weights_root, program_root and init_root. |
program, weights, tokenizer | Its SHA-256 equals the hash the stored manifest names for that file. |
So the manifest goes first, and nobody but the publisher decides what the files are: any file that does not hash to what was registered is refused, whoever uploads it.
| Status | Code | When |
|---|---|---|
| 400 | VALIDATION_ERROR | X-File is not one of the four kinds. |
| 409 | MODEL_NOT_REGISTERED | No Model account exists for the slug in X-Model, or a file other than the manifest arrives before the manifest is in the store. |
| 413 | PAYLOAD_TOO_LARGE | The file is larger than 67,108,864 bytes (64 MiB). |
| 422 | ROOT_MISMATCH | The manifest does not hash to files_hash or names other roots, or a file is not the one the manifest names. |
| 429 | RATE_LIMITED | More than 30 writes in a minute from one client. The response carries retryAfterSeconds. |
Every failure is the API's error envelope with stage: "upload", except the rate limit and a body over 64 MiB, which carry stage: "validation". HTTP API describes the envelope. The CLI stops at the first failed upload and prints the code and message. Running laplace model publish again on the same folder skips the registration and uploads the files.
What the publisher pays
| Cost | Amount |
|---|---|
The register_model transaction | One signature's fee. |
The Model account | The rent-exempt deposit for 231 bytes, taken from the publisher's wallet. |
| The uploads | Nothing. POST /v1/files takes no payment and no signature. |
The publisher posts no bond. The bond set here is what each answerer locks behind an answer to this model, and what each challenger posts to dispute one.
After publishing
The model has an account, and its files are in the store.
| Where | What is there |
|---|---|
/models/<slug> | The model's page in the app: its roots, step count, window, bond, offers and receipts. |
GET /v1/models/:slug | ModelDetail: the registration, the manifest's description, the offers and the files. It answers NOT_FOUND until the manifest is in the store. |
GET /v1/models/:slug/files | The hash, size and URL of the manifest, weights, program and tokenizer. |
GET /v1/files/:hash | The bytes of any of them. |
The model answers nothing until an operator serves it. An operator sets an offer for the slug and starts a node that holds it:
laplace operator offer <slug> <price> --mint <mint>
laplace serve --models <slug>The node reads the model's file list from the API, downloads program.bin and weights.bin by hash, checks each against its hash and keeps them in its data folder. A watcher does the same with laplace watch --models <slug>. Run a node and Run a watcher are the guides.