Inference functions
How model functions are declared, priced and paid for, step by step.
AI / The basics
AI models can be resources on Stellarium, just like any other API. You call them from RequestScript, pay per token in USDC, and don't need an account with each provider. Anyone who runs a model can offer it to the network and get paid for every call.
01 / Models as resources
On Stellarium, every API is a resource hosted by some node. A resource has a name, like com.example.Weather, and a list of functions that programs can call. See What is Stellarium? if you're new to these ideas.
An AI model fits the same shape. A provider wraps the model in a resource with a function that takes a prompt and returns text. For example, sh.stellarium.inference.claude.Sonnet offers Claude Sonnet through a message function. Its node tells the network about it, and every other node can route calls to it.
So AI gets everything the network already does: discovery by name, routing between peers, results that carry a value or an error, and payment with no sign up or API keys.
02 / Calling a model
Calling a model looks like calling any other function. This request asks Claude Sonnet for a haiku. The one difference is maxTokens: every model function takes it, and it sets the most output tokens the call may produce.
request AskClaude {
const sonnet: sh.stellarium.inference.claude.Sonnet
const reply = sonnet.message(prompt: "Write a haiku about Oslo", maxTokens: 200)
if (reply.error != null) {
return reply.error.message
}
return reply.value
}Your node handles the rest. It finds the node that hosts the model, gets a price estimate, checks it against your spending limit, and pays for the call. If the model fails, you get an error your script can handle instead of a failed request.
Because a model is a resource like the others, a single request can mix model calls with the rest of the network, such as a weather lookup or a price feed, and use their results together.
03 / Paying per token
Most paid resources charge a flat amount per call. AI doesn't work that way, because a call's cost depends on how many tokens go in and come out. Model functions are inference functions, priced at a rate per million input tokens and a rate per million output tokens.
Rates are public. Every model on the network lists its prices in GET /v1/resources, so you can compare models on the registry before you call one.
04 / Hosting a model
If you can run a model, or call one you have access to, you can offer it on Stellarium. Run a node, register a resource whose function is declared as an inference function, and set your per-token rates. Your function reports the tokens each call used, and the network settles payment to your wallet in USDC.
You only write two pieces of code: the function that runs the model, and an estimator that counts a call's input tokens. Billing, sign up, keys and discovery are handled by the network.
05 / Go deeper
How model functions are declared, priced and paid for, step by step.
Set up the node that hosts your model, from an empty folder to a running server.
Browse the resources on mainnet, including the models and their per-token rates.
Ready to put a model on the network?
Host a model →