API clients
Run tokens, script tokens and how a billed run is held and captured.
AI / Autonomous agents
An agent can do more on Stellarium than call APIs. With one set of credentials, it can write and run its own requests, deploy contracts other programs can call, declare events and structs, and react to what happens on the network, all inside a budget you set.
POST /v1/runstellarium deploy01
An agent acts through an API client. A person does this part once: an organization admin adds funds and creates the client for one node on the Stellarium Platform, setting the most one run may cost and an optional monthly cap. After that, the agent works on its own.
The node you choose decides what the agent can do:
| Your organization's node | Another organization's listed node | |
|---|---|---|
| Run requests | yes, no script charge | yes, at the node's price per million script tokens |
| Deploy contracts | yes, free | yes, plus the node's deploy fee, if it has one |
| Deploy event contracts | yes, runs are free | yes, billed per event under a mandate |
| Declare event types and structs | yes | no |
| Emit events | yes, for event types you own | no |
The agent exchanges the client ID and secret for a run token:
TOKEN="$(curl -s -X POST https://operator.stellarium.sh/v1/oauth/token \
-d grant_type=client_credentials \
-d client_id="$STELLARIUM_CLIENT_ID" \
-d client_secret="$STELLARIUM_CLIENT_SECRET" \
| jq -r .access_token)"A run token lasts 15 minutes and works on any number of runs, but only on the node its client was created for. When it expires, the agent asks for a new one. To use several nodes, give the agent one client for each.
02
Before writing any code, an agent can read what the network offers. These routes need no authorization, and return one page at a time with a nextOffset:
curl "$STELLARIUM_NODE_URL/v1/resources?limit=500"
curl "$STELLARIUM_NODE_URL/v1/contracts?limit=500"
curl "$STELLARIUM_NODE_URL/v1/events?limit=500"
curl "$STELLARIUM_NODE_URL/v1/structs?limit=500"Resources come with descriptions, parameter types, return types and prices, so a model can choose a function and call it correctly from the listing alone. Contracts also include their full source, so the agent can read exactly what one does before paying for it.
03
A request is a one-off RequestScript program, and the quickest way for an agent to act. The agent writes the script, sends it, and reads the result. Nothing is deployed. One request can call any number of resources, including AI models.
request AskSonnet {
const sonnet: sh.stellarium.inference.claude.Sonnet
const reply = sonnet.message(prompt: "Name one use for a weather API", maxTokens: 200)
if (reply.error != null) {
return reply.error.message
}
return reply.value
}curl -X POST "$STELLARIUM_NODE_URL/v1/run" \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' \
-d "$(jq -n --rawfile source AskSonnet.req '{source: $source}')"{ "returnValue": "Plan a delivery route around storms", "usage": { "tokens": 31 } }RequestScript has no loops, so the most tokens a script can execute is known before it runs. A generated script can't spin forever, and one that would cost more than the client allows is refused before it starts.
04
When a request is worth keeping, the agent can deploy it. Deployed code stays on the network, where other programs can use it after the agent's session ends.
| Deploy a | When the agent wants to | Route |
|---|---|---|
| Struct | name a data shape every node can check | POST /v1/structs |
| Event type | announce that something happened | POST /v1/events |
| Contract | publish a function anyone can call | POST /v1/contracts |
| Event contract | run code whenever an event arrives | POST /v1/contracts |
Here, an agent publishes a summarizer. It writes one declaration per file in a directory:
struct com.example.Digest@1(topic: string, summary: string)event com.example.DigestReady@1(digest: com.example.Digest@1)contract com.example.Summarize@1 {
const sonnet: sh.stellarium.inference.claude.Sonnet
pub fn summarize(topic: string, text: string): com.example.Digest@1 {
const reply = sonnet.message(prompt: "Summarize in one line: ${text}", maxTokens: 400)
if (reply.error != null) {
var failed: com.example.Digest@1 = { topic: topic, summary: "unavailable" }
return failed
}
var digest: com.example.Digest@1 = { topic: topic, summary: reply.value }
emit com.example.DigestReady(digest: digest)
return digest
}
}contract com.example.OnDigestReady@1 consumes com.example.DigestReady@1 {
fn on(digest: com.example.Digest@1) {
var state(digest.topic) latest: string = ""
latest = digest.summary
}
}The Stellarium CLI is the simplest way to deploy them. It gets its own run token, and deploys structs first, then event types, then contracts, so each declaration can name the ones before it. --dry-run compares each file's declaration with the node without changing anything. --output agent prints plain text, and piped output is JSON by default.
npm install -g stellarium-cli
export STELLARIUM_NODE_URL=https://node.example.com # no /v1
export STELLARIUM_OPERATOR_URL=https://operator.stellarium.sh/v1
export STELLARIUM_CLIENT_ID=cli_...
export STELLARIUM_CLIENT_SECRET=cs_...
stellarium --output agent deploy --dry-run stellarium/
stellarium --output agent deploy stellarium/deployed struct com.example.Digest@1 stellarium/Digest.req
deployed event com.example.DigestReady@1 stellarium/DigestReady.req
deployed contract com.example.Summarize@1 stellarium/Summarize.req
deployed contract com.example.OnDigestReady@1 stellarium/OnDigestReady.req
summary: 4 deployed, 0 unchanged@2. Calls always run the latest version.05
A contract is a resource like any other. Once it's deployed, the agent, or any other program on the network, binds it by name and calls one of its functions, here summarize:
request SummarizeStandup {
const summarize: com.example.Summarize
return summarize.summarize(topic: "standup", text: "Shipped the fix. Docs are next.")
}When Summarize succeeds, it emits DigestReady. The event contract runs on its own, with no request from the agent, and stores the summary in contract state. State is private, so the agent reads it with its client:
curl "$STELLARIUM_NODE_URL/v1/contracts/com.example.OnDigestReady/state" \
-H "Authorization: Bearer $TOKEN"That gives the agent memory between sessions: state survives restarts, and it's saved only when a run succeeds. Events can also connect agents that know nothing about each other. Any organization can deploy an event contract for an event type that isn't restricted, on any node that knows the type.
06
Everything an agent spends comes from its organization's prepaid balance, in USD. Each run is held first, and only what it used is charged.
| Action | What the agent's organization pays |
|---|---|
| Run a request | the node's price for script tokens executed, free on its own nodes, plus any paid functions the script calls |
| Call an AI model | the tokens used, never more than the signed ceiling |
| Deploy a contract | the node's deploy fee, free on its own nodes |
| Call a contract | the tokens it executes and every paid call it makes, free in its own organization |
| Have its contract called | nothing: the caller pays |
| Emit an event | only the publishing run's tokens |
| Run an event contract | each run, under a mandate on other organizations' nodes, free on its own |
A contract is billed at its hosting node's listed price, and that node's organization earns it, so an agent's contract on your own listed node can earn when others call it.
07
An agent makes its own decisions, so set its limits before it starts. The network enforces these, whatever code the agent writes:
A few things need care from you, because the network won't catch them:
GET /v1/contracts returns every version, so an agent must never put a secret in a contract.08
Most failures tell the agent what to do next. A resource call that fails doesn't fail the run: it comes back as an error value the script can handle. These statuses come from the node itself:
| Status | Meaning | What the agent should do |
|---|---|---|
400 | The source is invalid or names an unknown struct or event type | Fix the source, using the error message |
401 | The token is invalid or expired | Get a new run token and retry |
402 | Over the max per run, the balance or the monthly cap | Don't retry as is: make the script cheaper, or ask a person |
403 | Not allowed for this organization, or the node was unlisted | Use a client of the node's organization, or another node |
409 | The version exists or the name is taken | Deploy a new version, or choose another path |
413 | The source is too large | Split the contract |
422 | The script failed while running, and is charged for what it executed | Read details and fix the script |
503 | The operator is unreachable, or the node isn't enrolled | Retry later |
The CLI reports the same kinds of failure as exit codes: 2 for configuration, 3 for authentication or a refused deploy, 4 for an invalid script or version conflict, 5 for a network error worth retrying, and 6 when the operator refuses the deploy fee.
09
Run tokens, script tokens and how a billed run is held and captured.
Check agent-written .req files on pull requests and deploy them on merge.
Add the Stellarium skill to Claude, so it can work with the network.
Building an agent on Stellarium? Tell us about it on Discord.