Set up the gateway
This walkthrough takes a model server on your host to a signed, paid route on Solana devnet. The onboarding wizard at /providers/onboard generates the same files from a form; this page explains each step so you can do it by hand.
1. Prerequisites
- A checkout of
cool-kids-do-ai/inference-marketplaceand Bun 1.4.5 or newer. Older Bun ignores the repository's lockfile. Rolling restarts need Linux. - The Solana CLI (
solana,solana-keygen) andspl-token, for keys and the payout account. - An inference server that speaks the OpenAI chat completions API (or the Anthropic Messages API) on a private address.
- A public HTTPS hostname that will forward to the gateway.
bun --version
bun install --frozen-lockfile
Run bun install from the repository root: the gateway resolves @im/protocol through the workspace.
2. Start or point at your model server
For example, vLLM on loopback with the same concurrency you will advertise:
vllm serve meta-llama/Llama-3.3-70B-Instruct --host 127.0.0.1 --port 8000 --tensor-parallel-size 2 --max-num-seqs 64
To try the whole path without a GPU, use the repository's simulator instead. It is OpenAI-compatible, reports usage, and serves the model name sim-llm:
bun demo/sim-provider/src/server.ts --port=8001 --max_concurrency=16
Do not expose the model server publicly. Anything that reaches it directly is served without payment.
3. Create the three keys
mkdir -p gateway/keys gateway/data
solana-keygen new --no-bip39-passphrase -s -o gateway/keys/listing.json
solana-keygen new --no-bip39-passphrase -s -o gateway/keys/receipt.json
solana-keygen new --no-bip39-passphrase -s -o gateway/keys/settler.json
chmod 600 gateway/keys/*.json
solana-keygen pubkey gateway/keys/listing.json
The last command prints your seller ID. Key files are JSON byte arrays; the gateway accepts a 64-byte Solana keypair (as written above) or a 32-byte Ed25519 seed.
| Key | Signs | If you lose it |
|---|---|---|
listing.json |
The listing and capacity reports. Its public key is your seller ID and is hashed into every route ID. | You become a new seller with new route IDs. Back it up. |
receipt.json |
Every receipt. Published in receipt_keys with a key_epoch. |
Rotate to a new epoch (operations). |
settler.json |
Redemption transactions; it is also the seller_settler that channels name. Needs SOL for fees. |
Rotate with retainedSettlers so existing channels still redeem. |
The gateway rejects a configuration where any two of these are the same key.
4. Fund the settler and create a payout account
The settler pays Solana transaction fees for every redemption:
solana airdrop 1 "$(solana-keygen pubkey gateway/keys/settler.json)" --url devnet
If the airdrop is rate limited, use the Solana devnet faucet.
The payout account is an SPL token account for the mint pinned by the settlement program. The program checks the mint on every redemption, so an account for any other mint cannot be paid. The current devnet deployment (program 2grG8aUKE1HRjE8FqG4h5C2tmfAUG7PLsS8yL4nKrjdW) uses the project's devnet test mint 2LYaM1PTo4WwkoUx87E4pV39vWPDsohWVLyjUyA4MLUu (6 decimals). Create an account owned by your Solana CLI wallet:
spl-token create-account 2LYaM1PTo4WwkoUx87E4pV39vWPDsohWVLyjUyA4MLUu --url devnet
The address it prints after Creating account is your payoutToken. One payout account serves every route of the gateway.
5. Generate a route nonce
Each route carries a random 32-byte nonce in lowercase hex. It makes the route ID unique; keep it fixed once published.
bun -e 'console.log(Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("hex"))'
6. Write gateway/gateway.json
Paths are resolved relative to this file. Replace PAYOUT_TOKEN_ACCOUNT, the nonce, the endpoint host and the model identity with your own values. revision should name the exact weights you serve, for example the Hugging Face commit hash.
{
"hostname": "127.0.0.1",
"port": 8787,
"rpcUrl": "https://api.devnet.solana.com",
"programId": "2grG8aUKE1HRjE8FqG4h5C2tmfAUG7PLsS8yL4nKrjdW",
"payoutToken": "PAYOUT_TOKEN_ACCOUNT",
"listingKeyFile": "keys/listing.json",
"receiptKeyFile": "keys/receipt.json",
"settlerKeyFile": "keys/settler.json",
"keyEpoch": 0,
"ledgerPath": "data/seller.sqlite",
"routes": [{
"nonce": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"endpoint": "https://gpu.example.com/v1/chat/completions",
"modelIdentity": {
"family": "llama-3.3-70b-instruct",
"revision": "WEIGHTS_REVISION",
"quantization": "fp8",
"serving": { "engine": "vLLM", "engine_version": "0.8.5", "gpu": "NVIDIA H100 80GB", "gpu_count": 2, "max_concurrency": 64 }
},
"schedule": {
"v": 1, "currency": "USDC", "unit": "micro-USDC",
"rates_per_mtok": { "input": 600000, "cached_input": 150000, "output_visible": 1800000, "output_hidden": 1800000 },
"per_request_fee": 50, "w_req_micros": 2000, "ack_timeout_ms": 5000,
"ttft_max_ms": 4000, "failure_billing": "none", "effective_from": 0
},
"policy": { "zdr": true, "region": ["us-east"] },
"backend": { "kind": "openai", "url": "http://127.0.0.1:8000", "model": "meta-llama/Llama-3.3-70B-Instruct" }
}]
}
What the gateway enforces at startup:
endpointishttporhttps, has no credentials, query or fragment, and its path is exactly/v1/chat/completions. Buyers call this URL; it must be your public HTTPS origin.nonceis 64 lowercase hex characters.- The schedule has
v: 1,currency: "USDC",unit: "micro-USDC",ack_timeout_ms: 5000andfailure_billing: "none"; every number is a non-negative safe integer. serving.max_concurrencyis at least 1. It is your advertised concurrency and the gateway's admission limit for the route.backend.urlis the base URL of your model server. The OpenAI adapter appends/v1/chat/completionsunless the path already ends with it, and always sendsbackend.modelas the upstreammodel.
For the simulator, use "backend": { "kind": "openai", "url": "http://127.0.0.1:8001", "model": "sim-llm" }. Every field is described in the configuration reference.
7. Start the gateway
bun services/gateway/src/cli.ts --config gateway/gateway.json
At startup the CLI reads the cluster genesis hash from rpcUrl to build the signing domain, warms its channel view, opens the ledger and prints:
Gateway listening on port 8787
Gateway ready on port 8787
If anything is wrong (missing key file, invalid route, unreachable RPC) it prints one line, Gateway startup failed; check --config, key files, route configuration and Solana RPC availability, and exits 1. It never prints key material.
To point every configured route at a different upstream without changing route identity or prices, add --backend http://127.0.0.1:8001. It replaces backend.url for all routes at once.
The onboarding wizard can also generate a Docker variant that runs the same command inside oven/bun:1 with the checkout mounted at /app. Inside a container, set "hostname": "0.0.0.0" so the published port reaches the listener.
8. Put HTTPS in front
The gateway speaks plain HTTP. Terminate TLS at an edge you control, with response buffering off so streamed tokens and the final im_receipt event are not held back, and a header deadline. An nginx server block:
server {
listen 443 ssl;
server_name gpu.example.com;
ssl_certificate /etc/letsencrypt/live/gpu.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/gpu.example.com/privkey.pem;
client_header_timeout 10s;
client_max_body_size 2m;
location / {
proxy_pass http://127.0.0.1:8787;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off;
proxy_read_timeout 180s;
}
}
client_max_body_size 2m matches the gateway's default requestLimit of 2 MiB. Keep proxy_read_timeout above the gateway's timeoutMs (120 s by default).
9. Check it
curl -s https://gpu.example.com/.well-known/inference-marketplace.json
curl -s https://gpu.example.com/im/v1/capacity
curl -si -X POST https://gpu.example.com/v1/chat/completions -d '{"messages":[{"role":"user","content":"ping"}]}'
The first two return signed JSON envelopes. The third must return HTTP 402 with {"error":{"code":"malformed_hold",...}}: the gateway refuses any request without a Hold. Then run the self-check and ask an indexer operator to pin your seller ID.