Skip to main content
Pi reads, writes, and executes commands inside the box. This example uses an OpenAI Chat Completions-compatible endpoint with tool support. Complete the workstation setup. Run all commands below on your workstation.

Create the box and install Pi

Save create.py. Before running it, replace <YOUR_MODEL_HOST> with your model endpoint’s hostname, without the scheme or path. The prompt reads the real model key on your workstation; only BoxLite’s Secret configuration receives it.
create.py
Install the agent:

Connect your model

Use an existing OpenAI Chat Completions-compatible endpoint with tool support. Set Secret.hosts in create.py to its hostname. Save models.json, replacing the API base URL and model ID; set the context and output limits to values supported by your model:
models.json
Keep the Secret placeholder unchanged. The real provider key stays outside the box. Upload the configuration:

Run a task

Check the file and Pi’s output. A JSON stopReason: "error" means the model request failed, even if the CLI exited with code zero. Pi is ready. Repeat the exec command with your own task. --no-session makes each call an independent turn.

Optional: wake on a request

This walkthrough creates a separate pi-http box with an authenticated POST /tasks endpoint. After two idle minutes, the box stops. Sending another task to the same URL starts the box and runs Pi again. Run every command below on your workstation, in one directory. You will create two source files and a local caller token. The token’s hash goes into the box; the real model key stays in BoxLite’s Secret.

1. Create the HTTP box

Save this as create-http.py. Its startup command waits for the files installed in step 3, then starts the service on every boot.
create-http.py
Use auto_stop=0 instead if you want this HTTP service to stay running. Keep the value shown to try automatic stop and wake. Use the same model endpoint and Secret settings as the CLI deployment above.

2. Save the HTTP service

Save the complete code below as server.mjs. Replace <MODEL_ID> with the same model ID from models.json. The service accepts {"prompt":"..."}, runs one Pi task at a time with a three-minute limit, and returns Pi’s JSON result. POST /tasks is this example’s application API.
server.mjs
Only give the caller token to clients allowed to run tasks in this box. Tasks have access to the files and network available to this box.

3. Install and start the service

Generate the caller token and its hash locally:
Keep http-token on your workstation and out of Git. Keep models.json from the model setup above. Install Pi, upload the model configuration, service and token hash, then register port 8080:
The saved startup command starts the service as soon as these files exist. It starts it again after every wake; no attached terminal is required.

4. Send the first task

Set PI_URL to the HTTPS URL returned by the last command. Keep this shell open for the wake-up check.
If the service is still starting, retry this health request after a few seconds. Then ask Pi to create a file:
Success means the response contains "ok": true and the independent file check prints PI_HTTP_READY.

5. Wait for automatic stop

Stop sending HTTP requests, including health checks. Run only this control-plane check until Status is stopped:
Allow two idle minutes. Do not use start, exec, or cp before the next request: the HTTP request should be the action that wakes the box.

6. Wake Pi with another task

Send a new task to the same URL:
Cloud starts the box; its saved command starts the HTTP service, which runs Pi. After the response, check both files:
The first file checks retained work; the second checks that Pi ran tools after wake. Leave the box idle again and it stops automatically. The file checks verify real tool execution and retained work across a stop and wake. If Cloud returns 503 BOX_STARTING, wait for Retry-After before retrying. The service returns 401 for a wrong caller token and 409 while another task is running. A timed-out request can have partial effects: inspect its output before resubmitting it.

7. Clean up the HTTP box

For applications that already use Cloud exec, the CLI command above also supports wake on access; this HTTP service is optional.

When you are finished